Jump to content

Photo

Scripting: check with this array functions

scripting array function find between compare

  • Please log in to reply
No replies to this topic

#1
FrankFamily

FrankFamily

    The Evil Blacksmith

  • Supporter
  • PipPipPipPipPip
  • 6,953 posts

So in my recent scripting adventures i found myself needing to know if there was a a value between to indexes in my array. There's find and rfind both have a starting index parameter but not a stop index so i made this:

Bool Function FindBoolBetween(Bool[] ArrayToSearch, Bool BoolToLookFor, Int LowerLimit, Int UpperLimit) ; both included.
Int FirstElement = ArrayToSearch.Find(BoolToLookFor, LowerLimit)
If (FirstElement >= 0) && (FirstElement <= UpperLimit)
return True
Else
return False
Endif
EndFunction

Is the logic right?

Also, the native find functions works for any element type, can i make mine do so? or i would need to make another funcion with all bools as ints?

 

While i am at it, little thing about another function (not really, just a part of one), to compare whole arrays against some predefined set of values i'm casting them to string:

;VARS
String String1 = "[-1, 1, 2, 0, -1, -1, 3, 4, 5]"
String String2 = "[-1, 1, -1, 0, 2, -1, 3, -1, 5]"

; PIECE OF THE FUNCTION
If MyArray as string == String1
; do whatever
ElseIf MyArray as string == String2
; do another thing
Endif

And it seams to work, not sure how long the array can be without the string being truncated with "..." but mines are rather short and all trace tests gave the whole array.

But what about comparing two arrays?

If MyArray as string == MyArray2 as string

or does this work with arrays (i asummed it doesn't)

If MyArray ==  MyArray2

Thanks in advance for any help in the matter and if the function is indeed right, anyone is free to use if they find it useful i guess.


Edited by FrankFamily, 11 December 2015 - 10:29 PM.






Also tagged with one or more of these keywords: scripting, array, function, find, between, compare

Page loaded in: 1.080 seconds