0
\$\begingroup\$

I have a variable called global.goldchance = irandom(99);. I use it to get a random number from 0 to 99. However, I need to be able to run it again so that the variable gets a new random number. Writing var goldchance = irandom(99); doesn't work as that will destroy the variable afterward. Simply writing the global variable again in a new location won't work as that is just stating it and doing nothing with it. How do I do this?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Share your code and try to state what exactly you are trying to do in the first place. \$\endgroup\$ Sep 26, 2021 at 13:07
  • 1
    \$\begingroup\$ Presumably you tried writing global.goldchance = irandom(99); a second time when you want to generate a new random number to store in it? What went wrong when you tried that? \$\endgroup\$
    – DMGregory
    Sep 26, 2021 at 13:34

1 Answer 1

1
\$\begingroup\$

If you want to change the value of a GLOBAL variable you would just assign it a new value the same you would with a normal variable. You would just insert:

    global.goldchance = value;

"Simply writing the global variable again in a new location won't work as that is just stating it and doing nothing with it." -- Yes it will, as long as you're assigning a value to it.

\$\endgroup\$
1
  • \$\begingroup\$ Didn't realize this was posted two years ago. I assume you've already found the answer at this point. \$\endgroup\$
    – Vividlee
    Dec 19, 2023 at 13:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .