variable for all script in the editor
- montagneyaya
- Posts: 103
- Joined: Tue May 01, 2012 11:08 pm
variable for all script in the editor
Is there a way for create a variable usable in all script in the editor ?
Door on floor placement: http://grimrock.nexusmods.com/mods/120
Re: variable for all script in the editor
You can refer to a variable in another script entity without problems, prefixing it with the name of the entity followed by a dot ".".
If you can't write it (I haven't tested) you can put a couple of methods in that entity to wrap the variable (this is a good practice anyway and is the reason I didn't test the variable access really).
If you can't write it (I haven't tested) you can put a couple of methods in that entity to wrap the variable (this is a good practice anyway and is the reason I didn't test the variable access really).
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com
The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563
My preciousss: http://www.moonsharp.org
The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563
My preciousss: http://www.moonsharp.org
Re: variable for all script in the editor
I'm not positive but I seemed to not be able to affect the variable from another script entity, only read it. So if I had
badLunchScript which contained:
Then I can have another script entity in the dungeon called goodDinnerScript which contains:
but the only way to change the variable hotDogs is to do it inside badLunchScript. So if I'm still in goodDinnerScript, I can write this:
badLunchScript which contained:
Code: Select all
hotDogs = 4
applePie = 8
function eatSomeLunch()
hotDogs = hotDogs - 1
applePie = applePie - 1
endCode: Select all
peptoBismolSpoons = 0
function setSpoons()
peptoBismolSpoons = badLunchScript.hotDogs
endCode: Select all
badLunchScript.eatSomeLunch()Finished Dungeons - complete mods to play
Re: variable for all script in the editor
I'm pretty sure you're right Komag as I remember reading that you can only modify a variable from the script entity it is in.
Should be pretty easy to set up a few function to do it though.
then call something like:
Should be pretty easy to set up a few function to do it though.
Code: Select all
my_variable = 0
function incrementMyVariable()
my_variable = my_variable + 1
end
function decrementMyVariable()
my_variable = my_variable -1
end
function setMyVariable(x)
my_variable = x
end
Code: Select all
my_script.setMyVariable(5)Puzzle Frameworks - http://www.grimrock.net/forum/viewtopic.php?f=14&t=4564
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
- montagneyaya
- Posts: 103
- Joined: Tue May 01, 2012 11:08 pm
Re: variable for all script in the editor
Ok thank you all for this info
It will be a great help
It will be a great help
Door on floor placement: http://grimrock.nexusmods.com/mods/120
Re: variable for all script in the editor
Yup! Coincidentally, using "getters" and "setters" like these is often regarded as a good programming practice anyway even if you would be working in an environment where you could directly modify pretty much any variable. This way you can, for example, expand and build additional logic into the getter and setter functions later on so that you could build a check that a variable stays within a certain range and so on. 
Steven Seagal of gaming industry
