Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Check if 4 local int variables all carry different values?
HappyMatt12345 Offline
Junior Member

Posts: 16
Threads: 6
Joined: Oct 2018
Reputation: 0
#3
RE: Check if 4 local int variables all carry different values?

(11-19-2018, 11:37 PM)Mudbill Wrote:
PHP Code: (Select All)
SetLocalVarInt("Area1Num"RandInt(19));
SetLocalVarInt("Area2Num"RandInt(19));
SetLocalVarInt("Area3Num"RandInt(19));
SetLocalVarInt("Area4Num"RandInt(19)); 

This code will generate 4 numbers between 1 and 9. There's no guarantee that these will be different numbers, so you need to make sure they are.

A quick and dirty way would be changing the ranges to for example 1-3, 4-5, 6-7 and 8-9, however that would give it a fairly clear pattern.

I might've done something like this:

PHP Code: (Select All)
for(int i 1<= 4i++) // Loops 4 times
{
 
   int random RandInt(19); // Generate a random value
 
   
    while
(RandomValueExists(random)) // If value has been generated before
 
   {
 
       random RandInt(19); // Try to generate another
 
   }

 
   SetLocalVarInt("Area"+i+"Num"random); // Set the value


PHP Code: (Select All)
bool RandomValueExists(int value)
{
 
   for(int i 1<= 4i++)
 
   {
 
       if(value == GetLocalVarInt("Area"+i+"Num")) return true;
 
   }
 
   return false;


Adding in a debug message after the setter gives me this:
[Image: NdM68c3.png]
Thank you, this works and is more compact than an if statement with a ton of conditions. I need to learn more about utilizing variables and return statements clearly.

Developer of Order of the Skull
11-20-2018, 01:08 AM
Find


Messages In This Thread
RE: Check if 4 local int variables all carry different values? - by HappyMatt12345 - 11-20-2018, 01:08 AM



Users browsing this thread: 1 Guest(s)