PDA

View Full Version : Do Script variables retain their value after save and quit?



Floundermaj
11-29-2013, 09:36 AM
Greetings,

I have a global script I want to accomplish as follows:

Link receives a special equipment item that is permanently assigned to a scripted input (say EX1), which can be toggled on or off. When the item is "on" certain other of Link's items cannot be used, and he can access the special ability granted. When the item is "off", Link has access to all his items except the special ability.

The only way I know how to enable/disable items is to give them or take them away via script. (Link->Item(123) = true or false;) However, I do not want to give an item that link has not yet obtained from a dungeon, and I do not want to accidentally remove items permanently. I'm afraid this might happen if someone saves and quits while having the special item toggled "on".

So what I was thinking is to have a Boolean variable that corresponds to each item, and once that item is picked up from a dungeon, it is permanently equal to true. However, if someone saves and quits, will this true value be retained then next time they play? Is there another way to accomplish this?

Any help would be appreciated, Thanks in advance.

Saffith
11-29-2013, 12:35 PM
Global variables are saved. Just keep in mind that any changes to global variables will invalidate existing saves, since the game doesn't keep track of which one is which.

Zim
11-30-2013, 04:54 PM
Another easy way to make sure anything like this doesn't happen to you is as follows:

There is only one item change necessary, and you don't need to lose the item.
Make the item state true by whatever method, Link->Item[SPECIAL_ITEM_NUMBER]=true; for example, or picking it up normally in ZC.


import "std.zh";
global script SPECIALITEM
{
int ITEMSTORE[143];//Set an array of integers named ITEMSTORE[0] through ITEMSTORE[143];
bool ITEMDISABLE;//Creates a boolean ITEMDISABLE;
void run()
{
if(HasPlayed == false) //States that if this is the first time the game is ran, the function(s) below in brackets are called.
{
for(int i=0;i<=143;i++)
{ITEMSTORE[i]=0;ITEMDISABLE=false;}//Sets every int in the array ITEMSTORE[143] to 0, ITEMDISABLE to false, for 1st startup of game only.
//This is because the variables in the storage array must be declared and set to something once before they'll be assignable with a for.
}
//END of HasPlayed results.

while true()
{
if(Link->Item[SPECIALEQUIPMENTNUMBERFOREX1BUTTON]==true && Link->PressEx1 && ITEMDISABLE==false)
{ITEMDISABLE=true;
for(int i=0;i<=143;i++)
{
if(Link->Item[i]==true){ITEMSTORE[i]=1;Link->Item[i]=false;
}//This will set ITEMSTORE[i], where i is the number of the item(s) Link has, and remove Link's items.
}
if(Link->Item[SPECIALEQUIPMENTNUMBERFOREX1BUTTON]==true && Link->PressEx1 && ITEMDISABLE==true)
//You'll definitely be needed an extra integer, boolean, or make the special item ID number greater than 143 to make it exempt from being cancelled out with //the rest of the items.
{ITEMDISABLE=false;
for(int i=0;i<=143;i++)
{
if(ITEMSTORE[i]>0){Link->Item[i]=true;ITEMSTORE[i]=0;}//This will set ITEMSTORE[i] back to 0, and give Link back his items.b

}//while loop end
}//void run() end
}//Global Script End.
SPECIALITEMFUNCTIONS();
Waitframe();
}
}

void SPECIALITEMFUNCTIONS()
{
if(ITEMDISABLE==true)
{
//This is where you could write in all the functions Link can do while the special item is active, whatever they may be.
//These functions would kick in automatically since SPECIALITEMFUNCTIONS is called before the Waitframe() in the global script.
}
}


Edit: I added a fix to this code upon reading what I wrote. It needed a typo fix and another line.

Floundermaj
12-04-2013, 05:08 PM
Thanks this helps a lot. I think I have it sorted now. I'll post it if I get it working.