The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



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 How to search an array?
Cyfiawn Offline
Junior Member

Posts: 27
Threads: 8
Joined: Jun 2012
Reputation: 0
#1
How to search an array?

Hello,

I'm wondering how you can search an array for a certain value. I have declared my array: int[] bl(4,20);

I want to then set each array to a random, unique value, like so:
PHP Code: (Select All)
for(int i 03i++)    
{    
 
//set "bl[i]" to a random number between 0 and 7    
   
bl[i] = RandInt(07);     
//if another value in the array is already set to this number, re-randomise until it is unique.    
   
while(bl[i] == !!!Search array for the same value!!!)    
   {
       
bl[i] = RandInt(07); 
   }


Any ideas what I need to put in to search my array?

Also, it would need to not include itself in the search (ie. if i = 2, it needs to ignore bl[2] in the search and only include bl[0], bl[1] and bl[3].

I see on the AngelScript documentation it has "find(syntax)", but I'm unsure how to use it.

I have a kind of "hacky" solution. It works, but I'm sure there is a better way. I'll use this for now, unless anyone can come up with some cleaner code.

Also, copy and pasting code from Notepad++ loses its formatting on this forum...kinda annoying. >_>
PHP Code: (Select All)
    for(int i 04i++)
    {
bl[i] = RandInt(07);
if(
== 1)
{
while(
bl[i] == bl[0])
{
bl[i] = RandInt(07);
}
}
if(
== 2)
{
while(
bl[i] == bl[0] || bl[i] == bl[1])
{
bl[i] = RandInt(07);
}
}
if(
== 3)
{
while(
bl[i] == bl[0] || bl[i] == bl[1] || bl[i] == bl[2])
{
bl[i] = RandInt(07);
}
}

    } 
(This post was last modified: 07-11-2012, 07:08 PM by Cyfiawn.)
07-11-2012, 06:18 PM
Find


Messages In This Thread
How to search an array? - by Cyfiawn - 07-11-2012, 06:18 PM
RE: How to search an array? - by SilentStriker - 07-11-2012, 07:13 PM
RE: How to search an array? - by Cyfiawn - 07-11-2012, 07:18 PM
RE: How to search an array? - by Your Computer - 07-11-2012, 09:28 PM



Users browsing this thread: 1 Guest(s)