To keep it short, let's say they are not unchangeable (meaning the names can change but the position of each parameter means something).
Let's clear this out, a function recieves information from the outside, this information is given by the parameters, this is handled by TFS, you don't need to pay attention to this, what you have is the info that's neccessary to make your scripts.
The onUse function applies to WHATEVER thing you want to, toPosition is the position of the thing you use, it may not be neccessary for pulling a lever (or maybe if you want to add an effect on the lever position then it is!!).
Take the parameters as information given to you:
item -> This is the item given to you
item.itemid is the itemid ; item.actionid is the actionid ; item.uid is the uniqueid
fromPosition -> This is the position of the player!!
fromPosition.x is the x coord ; fromPosition.y is the y coord ; fromPosition.z is the z coord
If you were to "see" fromPosition it would look like: fromPosition = {x = getplayerpos.x, y = getplayerpos.y, z = getplayerpos.z}
itemEx -> Exactly what you said, this is the use with.. e.g using a potion onto someone/something
itemEx.itemid is the itemid ; itemEx.actionid is the actionid ; itemEx.uid is the uniqueid
toPosition -> Same as fromPosition but now the position is the position of the thing you used
Just rememer, everytime you use something that is registered in your actions.xml, it will come to the specific script and RUN the onUse function you defined, when it runs it, it will give YOU the information stored (cid, item, frompos, ...) in the parameters. Then you define a script for the hypothetical information that is to come!
For example, if you make an item that teleports you but you can only use it in a specific position, you are gonna be using fromPosition to check if you are at the correct position when using the item.
(This is not exactly the case, it is much more technical BUT let's keep it like this)
No, when the variable hits four the same script will add the ladder. But remember that after adding the ladder what happens to the levers?? Do they become unmoveable? After the ladder is created when pulling a lever does it remove the ladder? This has to be handled in the lever script aswell.
Global storages are what you need to make a global variable.
I'm sure (or I hope that) you know what storages are, they are just keys with specific values stored. In TFS 1.1 I think they are not handled by the database anymore, but it doesn't matter, you must think them as global variables, that is variables that are there for any script that wants to access them.
with Game.getStorageValue you get the current state of that global variable (that is your counter!!) and with Game.setStorageValue you set the value of that storage to whatever you want (increment or decrement the value). You NEED global variables because you MUST reset the counter when using the ladder script (the second script, ladder use).
This is how they look like:
Code:
Game.getStorageValue(storage)
Game.setStorageValue(storage, value)
So let's say I want to increment the value of this storage: (remember empty storages are set to -1)
Code:
-- Set a variable to my storage
local storage = 1231
-- First I check if my storage is empty, if it is (first use) then set it to zero (because I want the counter to start at zero)
if(Game.getStorageValue(storage) < 0) then Game.setStorageValue(storage, 0) end
-- Now I'm sure the storage starts at zero
-- If the player pushes then I increment:
Game.setStorageValue(storage, Game.getStorageValue(storage)+1)
-- If the player pulls then I decrement:
Game.setStorageValue(storage, Game.getStorageValue(storage)-1)
-- What's the state of my current counter??
print(Game.getStorageValue(storage))
Now this is the same as a local variable BUT the main difference is that you can actually access this stored value from another script, as long as you know the storage key (and you do because you set it up!!)
So at your second script you are gonna be updating the counter back to zero:
Code:
-- Since I know the storage key then I can access it from any script
local storage = 1231
-- Set the storage to zero
Game.setStorageValue(storage, 0)
Just think of global storages as a global variable, except this has a storage key and for that specific key it has a value in it. This value stored in that specific key is gonna be your counter and it is accessible from any script.
That's pretty good tbh! It is exactly what you have to do.
Instead of testcount you are gonna be using global storages, so that you can later in the ladder script set the storage back to 0.
Doing testcount = testcount+1 is equivalent to Game.setStorageValue(storage, Game.getStorageValue(storage)+1)
The last is NEVER executed because it is outside the onUse scope!! The function will execute and will leave at the end of it's scope, that is the end after the return TRUE. That should be inside the onUse function (actually everything that will happen must be inside the function, except for variable/tables/etc.)
You are gonna have to use toPosition (the position of the lever). I'm not sure if doCreatureSay would work in this case, I don't think so..
Not sure what would.