Results 1 to 6 of 6

Thread: Updating variables

  1. #1

    Question Updating variables

    How would I go about declaring a variable, and then having it update properly? As in, with this little ditty, it'll print my buffed moxie, use the tomato juice (changing my actual buffed moxie), and then print the same number again. I'd prefer it printed an accurate number the second time!

    int moxie = my_buffedstat($stat[Moxie]);
    print (moxie);
    use(1, $item[tomato juice of powerful power]);
    print (moxie);

  2. #2
    Senior Member
    Join Date
    Aug 2015
    Posts
    160

    Default

    I'm not an expert, but if ash scripting is anything like most languages, that code is setting moxie to the value of my_buffedstat($stat[Moxie]); at the time, not tying the variable to change with it. There may be some equivalent to an alias command, or you could just use the same call again.

  3. #3
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    454

    Default

    I'm not an expert, but if ash scripting is anything like most languages, that code is setting moxie to the value of my_buffedstat($stat[Moxie]); at the time, not tying the variable to change with it. There may be some equivalent to an alias command, or you could just use the same call again.
    Originally Posted by Laserrobotics View Post
    That's correct.

    Code:
    int moxie = my_buffedstat($stat[Moxie]);  // You're storing my_buffedstat($stat[Moxie]) in the intger called moxie
    print (moxie); // here you're printing what it has found
    use(1, $item[tomato juice of powerful power]); // This changes your moxie
    print (moxie);  // You're printing the number stored in the integer again.
    Try this:
    Code:
    int moxiebefore = my_buffedstat($stat[Moxie]); // This records before
    print ("My Moxie before: " + moxiebefore);
    use(1, $item[tomato juice of powerful power]);
    int moxieafter = my_buffedstat($stat[Moxie]); //This records after
    print ("My Moxie after: " + moxieafter); 
    int difference = moxieafter - moxiebefore; //Lets make an integer to do some math for us
    print ("Total boost of " + difference + " moxie points");//And here we see the difference that the tomato juice made
    Here's my output:
    My Moxie before: 615
    Using 1 tomato juice of powerful power...
    You acquire an effect: Tomato Power (10)
    Finished using 1 tomato juice of powerful power.
    My Moxie after: 905
    Total boost of 290 moxie points

    Hope this helps.
    Scripts I have written:
    Unlock Dread A Script to save you a bunch of clicks.
    Standard Rollover Bonus A Script that shows best items to pull/equip for bonus turns.
    Standard PVP Bonus A Script that shows the best items to pull/equip for bonus PVP Fights.
    Rollover Management A Script that does all the daily deeds you might have forgotten, or might have missed.
    Chatbot A Chatbot script. Simple start for those who want/need one for their clan.
    Zap Wand A Dungeon of Doom ZAP WAND getting script.

  4. #4

    Default

    Without any context for what you are trying to do, I suspect that you should be using my_buffedstat($stat[Moxie]) each time you need it instead of assigning it to a variable.

  5. #5
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    454

    Default

    Looking at it again, you don't even need to make it an int.

    print(my_buffedstat($stat[Moxie]));

    will do the exact same thing. Just call it twice.

    Code:
    print(my_buffedstat($stat[Moxie]));
    use(1, $item[tomato juice of powerful power]); 
    print(my_buffedstat($stat[Moxie]));
    The only reason I can think of storing it in an int is if you want to save the number, to recall it later, even if it's changed.

  6. #6
    Senior Member Crowther's Avatar
    Join Date
    Nov 2006
    Posts
    1,444

    Default

    How would I go about declaring a variable, and then having it update properly? As in, with this little ditty, it'll print my buffed moxie, use the tomato juice (changing my actual buffed moxie), and then print the same number again. I'd prefer it printed an accurate number the second time!

    int moxie = my_buffedstat($stat[Moxie]);
    print (moxie);
    use(1, $item[tomato juice of powerful power]);
    print (moxie);
    Originally Posted by princessqueso View Post
    To me it sounds like you want a function. This does what you want with little changes to your code.
    Code:
    int moxie() { return my_buffedstat($stat[Moxie]); }
    print (moxie());
    use(1, $item[tomato juice of powerful power]);
    print (moxie());

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •