Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / type array booleans

Author
Message
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 24th Nov 2006 08:43 Edited at: 24th Nov 2006 08:45
i'm about to add some primitive a.i. to my fps and i am trying to get the hang of type array booleans. i want to print "IDLE" initially, then "CHASING" when mouseclick()=2 and then "IDLE" again when mouseclick()=1, but it keeps saying "array does not exist or array subscript out of bounds at line 22."


jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 24th Nov 2006 10:09
for x = 1 to 1 will never execute even one time. Arrays are zero based, so you need to start at zero. I would further recommend that you abandon booleans for state machine management. They are not very flexible in that they are simply on, or off. You need to have more states than two, don't you? I would recommend that you use integers, and define constants for states. It will serve your needs better, and also, too many booleans is not very efficient memory use, either. You can use select/case with the symbolic state names, which will keep your state logic looking clean, like it does now.
Cheers.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Nov 2006 10:37
Quote: "for x = 1 to 1 will never execute even one time"


It will run once...



Jinzai is right about using states, which would look like this in your code:



This only works for mutually exclusive states. That is, only one can be true at any given time. If 2 things can happen together (e.g chasing and shooting), then you need additional variables for the states.



Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 26th Nov 2006 08:01
Quote: "I would recommend that you use integers, and define constants for states."


i have seen constants before but wasn't quite sure how to use them but i think i get the picture now...

Quote: "for x = 1 to 1 will never execute even one time. Arrays are zero based, so you need to start at zero"


i have heard this many times in the past but it has worked fine for me starting from 1...

i took jinzai's advice anyways, on starting from 0 and the same error keeps coming up.
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 26th Nov 2006 18:43 Edited at: 26th Nov 2006 19:03
Well, I was not being clear...I meant that it would not initialize the first element of the array, not...it won't run...my bad. Tks to BatVink for keeping it straight.

I did not look very closely at the code, and I made the same error that you are making, but...let's clear up the trouble with array subscripts first, because that is why I posted in the first place.

Array subscripts start with 0 in DBPro, so an array with a single element has only 0 for valid subscripts.

The error is on line 19 for me, which uses 'n' to reference the array. At that point in the code, n = 1, which is an illegal value, since the array has only one element, which is element 0. So, you can either use x like the loop does, or use n, but put it in the for/next lines....see what I mean?

You used n to initialize the array, and then you are using x in the loop definition, but n again in the body of the loop, therein lies the error. Also, I moved the state changing so that it is all in the proper place.

Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 27th Nov 2006 07:04
ok, i see now...thanks guys, i appreciate it.

Login to post a reply

Server time is: 2024-09-25 13:30:12
Your offset time is: 2024-09-25 13:30:12