Community Forum

"onCreate" scriptCallback problem

Forum Overview >> Farming Simulator 2011

CategoryFarming Simulator 2011
Created31.12.2010 14:33


Wojtek Speedy (Unknown) 31.12.2010 14:35
What did I do wrong that I'm this script does not work?

-- Drzwi Garazowe
-- Script by Speedy
-- www.mod.speedy.xaa.pl

DrzwiGarazowe = {};





function DrzwiGarazowe(id)
DrzwiGarazowe:load(id) --wczytaj funkcje load
print("Zaladowane drzwi garazowe");
end;
g_DrzwiGarazowe.DrzwiGarazowe("DrzwiGarazowe", DrzwiGarazowe);


function DrzwiGarazowe:loadMap(name)
end;

function DrzwiGarazowe:mouseEvent(posX, posY, isDown, isUp, button)
end;

function DrzwiGarazowe:keyEvent(unicode, sym, modifier, isDown)
end;


function DrzwiGarazowe:load(id)
self.triggerId = id; -- id triggera
addTrigger(id, "triggerCallback", self); -- dodaj trigger
self.deleteListenerId = addDeleteListener(id, "delete", self);
g_currentMission.controlPlayer = false; -- sprawdzenie czy gracz jest w triggerze "nie"
self.drzwi = getChildAt(id, 0); -- indeks drzwi
self.drzwi2 = getChildAt(id, 1); -- indeks drugich drzwi
self.koniecCzasu = 10000; -- koncowy czas otwierania
self.czas = 0; -- czas poczatkowy
self.otworzDrzwi = nil; -- czy drzwi otwarte
end;

function DrzwiGarazowe:deleteMap()
removeTrigger(self.triggerId);
removeDeleteListener(self.triggerId, self.deleteListenerId);
end;

function DrzwiGarazowe:update(dt)

if self.graczwtriggerze then -- jesli gracz w zasiegu triggera
if InputBinding.hasEvent(InputBinding.DRZWI) then -- mozliwosc wcisniecia klawisza
self.otworzDrzwi = not self.otworzDrzwi; -- otwieranie lub zamykanie drzwi
end;
end;

if self.otworzDrzwi then
self.czas = self.czas + dt;
self.czas = math.min(self.czas, self.koniecCzasu);
else
self.czas = self.czas - dt;
self.czas = math.max(self.czas, 0);
end;

setRotation(self.drzwi, 0, (110*(3.14159265/180))*(self.czas/self.koniecCzasu), 0);
setRotation(self.drzwi2, 0, (-110*(3.14159265/180))*(self.czas/self.koniecCzasu), 0);
end;
function DrzwiGarazowe:draw()
if self.graczwtriggerze then
if self.otworzDrzwi then
g_currentMission:addExtraPrintText(string.format("Klawisz %s: Otworz drzwi", InputBinding.getButtonKeyName(InputBinding.DRZWI)));
else
g_currentMission:addExtraPrintText(string.format("Klawisz %s: Zamkij Drzwi", InputBinding.getButtonKeyName(InputBinding.DRZWI)));
end;
end;

end;
function DrzwiGarazowe:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)

if onEnter then
print("otherId", otherId)
print("name", getName(otherId))
if otherId == g_currentMission.player then
g_currentMission.controlPlayer = true;
end;
elseif onLeave then
if otherId == g_currentMission.player then
g_currentMission.controlPlayer = false;
end;
end;

end;
addModEventListener(DrzwiGarazowe);

And so it looks like line in the attributes map:
<UserAttribute nodeId="12108">
<Attribute name="onCreate" type="scriptCallback" value="DrzwiGarazowe.DrzwiGarazowe"/>
</UserAttribute>
Please help and correct the error. Sorry for my english


Stefan Geiger - GIANTS Software 03.01.2011 10:12
What is this line supposed to do:
g_DrzwiGarazowe.DrzwiGarazowe("DrzwiGarazowe", DrzwiGarazowe);

You neither have specified an object called g_DrzwiGarazowe nor you have a function called DrzwiGarazowe taking a string and a table.

I assume the function DrzwiGarazowe is a function you wan to use as an onCreate function, right?
You might want to have a look at the following thread. There I have described the "correct" way to create a mod onCreate function:
http://gdn.giants-software.com/thread.php?categoryId=16&threadId=556


Note: Log in to post. Create a new account here.