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
Solved - Building an array with numbers 1-4 in random order.
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#1
Solved - Building an array with numbers 1-4 in random order.

Hey guys. Got a question for seasoned programmers. I'm trying to build an integer array with the numbers 1-4 in a random order. Having some trouble though. This particular bit of code doesn't have any syntax errors, but I'm worried about the semantics.

I ran the function with a debug message listing the order of the array it generates, but the debug message doesn't appear. I tried attaching a second debug message to at least let me know the function terminates, but apparently it just doesn't. I'm pretty sure it's because of the deeply nested while loop. Any suggestions on what I can do it get around this? Here's the code

PHP Code: (Select All)
void OnStart()
{
    
AddTimer(""2.0f"Test01CompileArray");
}
//pseudo callback I wrote to show how I run the function
void Test01CompileArray(string &in t)
{
    
UltDeathArray=CompileUltDeathArray();
    
//debug messages here
}
int[] UltDeathArray;
int[] CompileUltDeathArray()
{
    
int[] builder={0,0,0,0};
    
int temp;
    
int currIndex=0;
    for(
int i=1;i<=builder.length() ;i++)
    {
        
currIndex++;
        
temp=RandInt(1,4);
        for(
int j=1;j<=builder.length();j++)
        {
            while(
temp==builder[j-1]) temp=RandInt(1,4);
        }
        
builder[currIndex]=temp;
    }
    return 
builder;




(This post was last modified: 02-22-2012, 04:14 AM by palistov.)
02-22-2012, 03:30 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Building an array with numbers 1-4 in random order.

Turns out AngelScript doesn't automatically resize the array: http://www.frictionalgames.com/forum/thr...l#pid94394

Tutorials: From Noob to Pro
(This post was last modified: 02-22-2012, 03:43 AM by Your Computer.)
02-22-2012, 03:43 AM
Website Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#3
RE: Building an array with numbers 1-4 in random order.

I actually got it to work. It was because I started from index 1 when inserting the integers into the builder array instead of index 0. Didn't intend to automatically re-size, regardless of support. It's always the little things......

02-22-2012, 04:12 AM
Find




Users browsing this thread: 1 Guest(s)