How to assign a variable a random integer

Started by The_Eraser, May 24, 2018, 03:35:21 PM

Previous topic - Next topic

The_Eraser

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.

Fausto Mugen


The_Eraser

Just tried that and it didn't work. The player is always released after 1 struggle :(

Baby Bonnie Hood

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).

The_Eraser

#4
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

altoiddealer

#5
Quote from: The_Eraser on May 24, 2018, 04:24:44 PM
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:

[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


XGargoyle



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!

Jesuszilla

Yeah, VarRandom is better-suited for this sort of task, and it has more randomness than the Random trigger IINM.

altoiddealer

Quote from: XGargoyle on May 24, 2018, 06:45:17 PM
Use VarRandom

Edited my post to use VarRandom :)  Ah yes that's more simple for the range


The_Eraser

Wow thanks! I made a few tweaks and the code worked perfectly. Thanks a lot for the help! :)