Variable Checking Question

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

wild8900
New Member
Posts: 35
Joined: Mon 19 Sep, 2005 11:26 pm

Variable Checking Question

Post by wild8900 »

Hey how do you see if a variabe equals any number in a list or a matrix? (preferably on a list).
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

Is this from BASIC (as in a BASIC variable) or an ASM program checking a TIOS list/matrix?

Either way you would just need to traverse the list/matrix in a loop and compare it against your variable. But then there are of course cases where the number appears more than once in the list etc ...
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

If it's a list, don't use a loop!
for matrices, unfortunately, you'll have to use a loop..

Code: Select all

if sum(L1=X)
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.
User avatar
Super Speler
Regular Member
Posts: 113
Joined: Fri 09 Feb, 2007 2:20 am
Location: Alpha Centuri

Post by Super Speler »

max(L1=X is faster if it doesn't matter how many times it appears in the list.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

it's not faster, and like you said, you won't know how many times the value is in the list.
the TIOS will still have to loop through the whole list for max(
User avatar
Super Speler
Regular Member
Posts: 113
Joined: Fri 09 Feb, 2007 2:20 am
Location: Alpha Centuri

Post by Super Speler »

PROGRAM:TEST
:{0,1,0,1,0,1->L1
:startTmr->T
:for(A,1,E4
:max(L1
:End
:startTmr-T
Output: 48

PROGRAM:TEST
:{0,1,0,1,0,1->L1
:startTmr->T
:for(A,1,E4
:sum(L1
:End
:startTmr-T
Output: 56

I win.
threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

Super Speler, that test isn't accurate. He isn't saying sum(L1, he's saying sum(L1=X.

While adding the =X will undoubtedly make it slower, you should do it to make sure your tests are correct.
Image
User avatar
Super Speler
Regular Member
Posts: 113
Joined: Fri 09 Feb, 2007 2:20 am
Location: Alpha Centuri

Post by Super Speler »

No the =X is the same amount of time in each example leaving my test intact (I can test this if you want).
wild8900
New Member
Posts: 35
Joined: Mon 19 Sep, 2005 11:26 pm

Post by wild8900 »

Well you see, Its for my BASIC game and the list contains the tile numbers of the tiles that you CAN walk through. Constantly checking every step in a loop for each var in the list would be unplayable.
Floodkiller
Sir Posts-A-Lot
Posts: 245
Joined: Mon 14 Nov, 2005 9:47 pm
Location: Getting overwhelmed by everything
Contact:

Post by Floodkiller »

Ohhh, you mean collision detection :D.

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
I am sure you could do it a different way, but thats just the basics.
Main Projects:
Zombie Attack: 20%

Side Projects:
???-25%

Image

Staff member of Hikaru Rakuen Programming.
wild8900
New Member
Posts: 35
Joined: Mon 19 Sep, 2005 11:26 pm

Post by wild8900 »

No, I know how to do collision detection, I need to know how to see if a variable equals ANY number in a list without having to start a seperate loop.
User avatar
Super Speler
Regular Member
Posts: 113
Joined: Fri 09 Feb, 2007 2:20 am
Location: Alpha Centuri

Post by Super Speler »

Yes, max(List=Number, It's been said before in the thread.
wild8900
New Member
Posts: 35
Joined: Mon 19 Sep, 2005 11:26 pm

Post by wild8900 »

Oh sorry I didnt see your post, I was replying in response to Floodkiller.
Thanks! Ill try out your method.
User avatar
CDI
Maxcoderz Staff
Posts: 321
Joined: Tue 24 May, 2005 7:25 pm
Location: If I find out, you'll be first to know.
Contact:

Post by CDI »

Why not just have section of your pic for solid tiles, and a section for non-solid tiles. For instance, Metroid Infinity will have any tile in the top 2 rows be able to walk through, any tile in the 3rd row be for morph ball only, and anything below the 3rd row is solid
ImageImage
wild8900
New Member
Posts: 35
Joined: Mon 19 Sep, 2005 11:26 pm

Post by wild8900 »

Yeah I thought of doing that but then that would mean having to redo every single map in the game.... I might just end up doing that though.... >.>
I really dont look forward to redoing the maps....
Post Reply