Passing variables to an object script.

D4r4dragon
30 Jul 2021, 22:48Hello, it is me again, this was only a matter of time.
I want to pass variables to object scripts, in my case two integers labeled Allies
and Enemies
. But it looks to desire a dictionary... How do I go about making then using such?
mrangel
31 Jul 2021, 08:29The easiest way to make them into a dictionary is using QuickParams
, which makes a dictionary quickly. I think it was designed for doing stuff like this.
If Allies
and Enemies
are the names of variables, then the expression QuickParams ("Allies", Allies, "Enemies", Enemies)
will give you a dictionary containing those values. (The names in quotes are the names the variables will have if you pass this dictionary to do
, invoke
, or eval
. The second copy of each is the name of the variable in this function)
Most of the time, when you use QuickParams, you'll be doing something like this:
do (somecharacter, "doattack", QuickParams ("weapon", object1, "target", object2))
I think QuickParams can be used for up to 3 values. If you want more than 3, you would have to do something like:
params = NewDictionary()
dictionary add (params, "Allies", Allies)
dictionary add (params, "Enemies", Enemies)
dictionary add (params, "Fruits", Fruits)
dictionary add (params, "Vegetables", Vegetables)
do (someobject, "somescript", params)
(Edit: QuickParams works for 3 variables. I thought it was 4)