YesNoOk
avatar

How to assign a variable a random integer (Read 1941 times)

Started by The_Eraser, May 24, 2018, 03:35:21 pm
Share this topic:
How to assign a variable a random integer
#1  May 24, 2018, 03:35:21 pm
  • avatar
    • UK
So, I'm working on a character that someone else has made, doing a few edits and tweaks to make it play a little better. One of this character's moves means that the other player has to struggle to get free. Every time they struggle, the struggle counter goes up by 1. Previously, when the struggle counter reaches 8, the player would be released. I thought this was a bit streamlined and wanted to be able to randomise the amount of struggles someone had to do before they could escape. My main issue is that most of what I have found on here tells you how to assign a variable a random number, but I want the number of struggles needed to escape to be random, rather than the number of struggles, if that makes any sense.

The main part of the code that I'm focussing on is this:
[state 1004] ;release
type = changestate
triggerall = numtarget
triggerall = target, alive
trigger1 = var(4) = 8 && (var(5) = 1)
trigger2 = roundstate = 3
value = 1012

Var(4) is the variable dealing with the number of struggles. Therefore, "trigger1 = var(4) = 8" is saying "when the amount of struggles reaches 8, they will be released". The 8 is therefore the integer that I want to be randomised but, pretty much all my methods have been unsuccessful. I have managed to find out how to generally make the integer random, simply by doing this: "trigger1 = var(4) = random". This provided me with a random number of struggles needed to escape, but I would really like to define the range of numbers that can be picked, 1-16. I have tried lots of different things and either the game will be unable to load the character or the other player is released instantly without struggling. If anyone has any idea how I can set it so that var(4) = a random integer between 1-16 that would be fantastic!

Also, I should mention that I'm new to this site and I am also not great with coding.
Re: How to assign a variable a random integer
#2  May 24, 2018, 04:12:18 pm
  • **
  • I got tired of waiting for someone to do it for me
    • Argentina
var(4) = (Random % 16) + 1
Re: How to assign a variable a random integer
#3  May 24, 2018, 04:24:44 pm
  • avatar
    • UK
Just tried that and it didn't work. The player is always released after 1 struggle :(
Re: How to assign a variable a random integer
#4  May 24, 2018, 04:47:17 pm
  • ****
  • Cute Bounty Hunter
var(4) is the one that counts the struggles, right?  Then try using another var to track the max number of struggles, as in use something like var(3) for the random number and then have var(4) check if it's equal to var(3).
Re: How to assign a variable a random integer
#5  May 24, 2018, 04:50:49 pm
  • avatar
    • UK
um...I guess I'll try, but that sounds a little outta my league

Edit: Yeah, that's way too advanced for me. I was hoping this could just be solved with a simple command, but if I'm gonna have to start creating new variables and stuff I think I just won't bother. It's just quite frustrating because it seems like something that should be simple
Last Edit: May 24, 2018, 05:08:15 pm by The_Eraser
Re: How to assign a variable a random integer
#6  May 24, 2018, 05:42:55 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Just tried that and it didn't work. The player is always released after 1 struggle :(

This is because that snippet of code is picking a random number every tick (60 ticks per second), so it is very quickly picking "1"

For this, I would advise using another variable so it gets logged only 1 time.

Do you want to set a minimum/maximum amount of struggles?  Such as, must struggle 2 times / chance of triggering at 3-7 / definitely trigger at 8?

So what I'm suggesting would be:
Code:
[state 1004] ;pick random from 2-7
type = VarRandom
trigger1 = !time
var(6) = 2,7

[state 1004] ;release
type = changestate
triggerall = numtarget
triggerall = target, alive
trigger1 = var(4) > 7 && var(5) = 1
trigger2 = var(4) = var(6) && var(5) = 1
trigger3 = roundstate = 3
value = 1012

Use Ctrl + F (SEARCH) to search the character's code for "var(6)".  If it finds something, that means the character is already using that variable for something else.
So you would then repeat for var(7), var(8), etc... until you find one that is not being used

Last Edit: May 24, 2018, 08:23:40 pm by altoiddealer
Re: How to assign a variable a random integer
#7  May 24, 2018, 06:45:17 pm
  • ******
  • Hedgehog Whisperer
  • Red Bull addict
    • Spain
    • xgargoyle.mgbr.net
Use VarRandom
XGargoyle: Battle posing since 1979
http://xgargoyle.mgbr.net
http://www.pandorabots.com/pandora/talk?botid=e71c0d43fe35093a  <-- Please click that link
http://paypal.me/XGargoyle  <-- Donations welcome!
Re: How to assign a variable a random integer
#8  May 24, 2018, 07:22:52 pm
  • ******
  • Loyal to the Game
    • USA
    • http://jesuszilla.trinitymugen.net/
Yeah, VarRandom is better-suited for this sort of task, and it has more randomness than the Random trigger IINM.
Re: How to assign a variable a random integer
#9  May 24, 2018, 08:23:28 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com

Re: How to assign a variable a random integer
#10  May 24, 2018, 11:25:15 pm
  • avatar
    • UK
Wow thanks! I made a few tweaks and the code worked perfectly. Thanks a lot for the help! :)