View Full Version : Help localizing variables in script

01-26-2014, 12:02 AM
Hi. I have been trying out some methods Rochet mentioned when it comes to localizing the variables of a scripts but are having some trouble. I just want to make sure the script works while multiple groups in different instances are doing it at once, notably to prevent waypoint variables from overlapping each other.

Currently the OnMove function triggers but does not work, could anyone please help me understand and possibly show me how it would look if it were fully functional? If there is something else I have overlooked when it comes to localization I would highly appreciate any input.

Here's the script. (http://paste.emudevs.com/?paste=93)

01-26-2014, 08:30 AM
I edited the file a bit to test it and so. (used my own coords)
Try seeing http://pastebin.com/diff.php?i=MATpZm7r
about what changed. Note that it doesnt show all changes : |

I changed the index numbers by one up as in Lua table index starts at 1.
This means that when you move to waypoint 1, you will then trigger the coordinates in the lua table at index 1 (second waypoint)

Personally I would try to handle it without tables like this to pass the waypointID to the timed function to call MoveTo with the wpID:
Though, since you have events in between the waypoints, you would also need this trick:

What if I need to pass more variables than a function can receive :(?
In some situations you might want to pass additional arguments to functions.
This is often needed with timed events. This is also a useful trick for some situations :)

local function myFunction(eventId, delay, calls, customVar)
print(customVar) -- prints 123
CreateLuaEvent(function(a,b,c) myFunction(a,b,c, 123) end, 5000, 0)

Lua allows you to create functions inside a function. You can also store functions to a variable and tables and so.
Actually the function defining syntax is just a syntactic sugar to:
local myFunction = function(eventId, delay, calls, customVar) print(customVar) end

ps. You could also think of a way to remove the data for the creature from the table in the end of the waypoint cycle. Or when he despawns or something.

01-26-2014, 02:49 PM
Thank you very much for this. I will look into rewriting it with what you said in mind.