Need help with "GetRandomInt"

image

image

Shotty1 is a variable
Button1 is an button_device in the island

whenever Button1 is pressed, It will add +1 for Shotty1. And the same happens with Shotty2 when button2 is pressed.

When the voting period ends, If shotty1 is greater than shotty2 it grants a shotgun and it would grant a different shotgun if shotty2 was greater.
But what happens when they both are equal? that’s when I tried to use GetRandomInt to randomly choose between Shotty1 and Shotty2. Here is the screen shot:
image

BUT… the problem is… whenever the voting is calculated and weapons are being granted, Both Shotty1 and Shotty2 are granted. I have no idea why this happens and came to the conclusion that I’m using GetRandomInt wrong.

If anybody know why this is happening please let me know, I would appreciate any replies

Couple of rewrites:
set Shotty1 +=1

and
if(Shotty1 = Shotty2):
rng:int = GetRandomInt(1,2)
if(rng = 1):
do a thing
else:
do a different thing

Then just make sure this isn’t being called twice, because I think it is.

1 Like

Thank you, I appreciate your reply. I’ll make these changes and check if it’s working. I also think it’s running twice.

It works now, thanks to you. It was running twice because I overlooked something.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.