Variable Checking Question
Moderator: MaxCoderz Staff
Variable Checking Question
Hey how do you see if a variabe equals any number in a list or a matrix? (preferably on a list).
-
- Calc King
- Posts: 1513
- Joined: Sat 05 Aug, 2006 7:22 am
If it's a list, don't use a loop!
for matrices, unfortunately, you'll have to use a loop..
this will check the value of X against all values in L1, create a list with only 1's and 0's in it and sum it up, it there is any 1 in it then the condition will be regarded as "true", if NO VALUE in the list matches X then it will be FALSE, ofcourse you can put something like ">5" behind the sum() to make the number of required matches higher, or only cause 'true' if the number of matches equals a value, etc.
this is like 100 times as fast as a loop since the parser will only have to parse your line once and then execute the loop in asm.
For matrices, you can first split them up in lists and then use a loop as long as the number of lists, that would still be a lot faster then a nested loop over each element.
for matrices, unfortunately, you'll have to use a loop..
Code: Select all
if sum(L1=X)
this is like 100 times as fast as a loop since the parser will only have to parse your line once and then execute the loop in asm.
For matrices, you can first split them up in lists and then use a loop as long as the number of lists, that would still be a lot faster then a nested loop over each element.
- Super Speler
- Regular Member
- Posts: 113
- Joined: Fri 09 Feb, 2007 2:20 am
- Location: Alpha Centuri
-
- Calc King
- Posts: 1513
- Joined: Sat 05 Aug, 2006 7:22 am
- Super Speler
- Regular Member
- Posts: 113
- Joined: Fri 09 Feb, 2007 2:20 am
- Location: Alpha Centuri
-
- Calc King
- Posts: 2195
- Joined: Sun 27 Mar, 2005 4:06 am
- Location: sleeping
- Contact:
- Super Speler
- Regular Member
- Posts: 113
- Joined: Fri 09 Feb, 2007 2:20 am
- Location: Alpha Centuri
-
- Sir Posts-A-Lot
- Posts: 245
- Joined: Mon 14 Nov, 2005 9:47 pm
- Location: Getting overwhelmed by everything
- Contact:
Ohhh, you mean collision detection .
There is a good example in the xLIB demo provided, but a simpler, less optimized version would be:
I am sure you could do it a different way, but thats just the basics.
There is a good example in the xLIB demo provided, but a simpler, less optimized version would be:
Code: Select all
:If (X+#>0)(Y+#>0)(X+#<$+1)(Y+#<$+1)=1:Then - Replace X and Y with your character positions, the # signs added to your X and Y with numbers to tell the matrix where your character is moving, and the $ signs with the matrix limits
:If [A](X+#,Y+#)<@:Then - the @ is the first tile that you cannot walk through.
:[i]movement code[/i]
:End
:End
- Super Speler
- Regular Member
- Posts: 113
- Joined: Fri 09 Feb, 2007 2:20 am
- Location: Alpha Centuri