UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

[Utility Function] Searching an array

broken avatar :(
Created 11 years ago
by daedra descent
0 Members and 1 Guest are viewing this topic.
1,714 views
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
Signature
Let's keep this thread on topic from here on in. -DBZ

+1 to off-topic reply -DBZ

lmao. Too funny.

Goliath Script Placer: http://ugx-mods.com/forum/index.php/topic,11234.msg125257/topicseen.html#new

"...Christ, people. Learn C, instead of just stringing random characters
together until it compiles (with warnings)..."

-Linus Torvalds
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
Utility script that searches an array and if true, can either return true or return the index or if false will just return false. A function like this probably exists in the bowels of World at War's Utility and campaign scripts but i couldn't find it so i made my own which someone else may find useful so i decided to share it.

Function:
Code Snippet
Plaintext
// Searches through an array for something and returns either the index or a boolean
// Args:
// Array = the array you want to search
// item = the thing your trying to find in the array. MUST be the same data type as whats stored in the array
// type = what to return if true. Currently just allows to return the index spot(i).
//
search_array(array, item, type)
{
for(i=0;i<array.size;i++)
{
if(array[i] == item)
{
if(isdefined(type) && type == "index")
return i;
else
return true;
}
}
return false;
}

Small note: Make sure you specify the type if you want the index. If you don't, the function will either return 1(true) or 0(false) because thats what true or false evaluates to.

Edit: Actual code example:

Code Snippet
Plaintext
	index = search_array(level.weapons, getent("kar98k_scoped", "script_noteworthy"), "index");
Last Edit: June 12, 2015, 07:56:53 am by daedra descent
broken avatar :(
×
broken avatar :(
Location: usUnion, Kentucky
Date Registered: 9 September 2013
Last active: 3 years ago
Posts
310
Respect
Forum Rank
Perk Hacker
Primary Group
Box Mappers Elite
My Groups
More
My Contact & Social Links
More
×
lilrifa's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Box Mappers Elite
Box Mappers Elite
lilrifa's Contact & Social Linkslilrifaskypeuser724lilrifa
This looks great! I'll be sure to use it if necessary.

 
Loading ...