User Tag List

Results 1 to 4 of 4

Thread: Do Script variables retain their value after save and quit?

  1. #1
    Gel Floundermaj's Avatar
    Join Date
    Aug 2013
    Location
    Connecticut
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    486
    Level
    7
    vBActivity - Bars
    Lv. Percent
    94.76%

    Do Script variables retain their value after save and quit?

    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.

  2. #2
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    41
    Posts
    3,389
    Mentioned
    178 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,432
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70%
    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.

  3. #3
    Admiral Zim's Avatar
    Join Date
    Oct 2012
    Posts
    388
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    1,702
    Level
    13
    vBActivity - Bars
    Lv. Percent
    83.69%
    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.
    Code:
    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.
    Last edited by Zim; 01-14-2014 at 02:55 AM.

  4. #4
    Gel Floundermaj's Avatar
    Join Date
    Aug 2013
    Location
    Connecticut
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    486
    Level
    7
    vBActivity - Bars
    Lv. Percent
    94.76%
    Thanks this helps a lot. I think I have it sorted now. I'll post it if I get it working.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social