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.

DarkBASIC Discussion / tip or trick

Author
Message
Silverman
13
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 1st Sep 2012 17:32 Edited at: 1st Sep 2012 17:33
Hi all,
you can use this trick to simplify your source code :


@+

DirectX 9.0c (February 2010)/ DBClassic v1.20
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Sep 2012 05:10
I was messing around with this idea and found something odd/glitchy

See how the turning keys need to be =0, I don't understand that, the camera spins continually if they are set to the more logical =1. What's going on here?

Shh... you're pretty.
BN2 Productions
16
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 4th Sep 2012 05:18
Quote: "What's going on here?
"


I could be wrong, but doesn't SELECT exit once it hits a valid CASE statement?

Try this:

CASE (keystate(30)=0 OR keystate(32)=0) : turn camera left (keystate(30)-keystate(32) : endcase

Of course you could omit the SELECT statement altogether with this kind of logic, as if neither are pressed, it is turning left. So you could put:



Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th Sep 2012 10:20
@Obese

What is '.' evaluating to in the select portion? It may be undefined in this case or point to a NULL pointer. If it evaluates to a float, then it may not be making a reliable comparison to integer values being returned in the case conditional tests.

The numeric values in DBC are actually strings that are pointers to values. By default, the numbers point to values of themselves but you could easily change their value:



So you may not be getting the value you want with Select .

Also, logical conditional tests might not actually work in a case statement. They may only be triggered by the presence of a number or variable, like the 1 or the 0. If 1 is present the condition is true, if the zero is present the condition is false. So if your test after the case statement is (keystate(32)=0), it may only be picking up the 0 and returning a false. For a test, try setting the values to 5 or 6 or -29 and see what happens. I'm not at a computer with DBC right now so I can't test any of this.

Quote: "I could be wrong, but doesn't SELECT exit once it hits a valid CASE statement?"

No it doesn't. It evaluates all case conditions. That's why in long select case blocks, for speed I use a jump from the case block to the endselect:



Enjoy your day.
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Sep 2012 18:29 Edited at: 4th Sep 2012 18:30
@BN2
Run it and you'll see it acts as if it says case (keystate(32)=1) : turn camera left -1 : endcase, weird.

@Latch
Quote: "Also, logical conditional tests might not actually work in a case statement. They may only be triggered by the presence of a number or variable, like the 1 or the 0."

But they do work, the first two work fine and the second two work, except being the reverse of what you would logically think.

Quote: "What is '.' evaluating to in the select portion?"

DBC accepts it as 0.0 so I use it where numbers aren't important or converting an integer to a float (a# = a+.), I tried changing it to 0 but nothing changes.

Shh... you're pretty.
Silverman
13
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 4th Sep 2012 20:15 Edited at: 4th Sep 2012 20:30
I think it may be easier to understand as:



DirectX 9.0c (February 2010)/ DBClassic v1.20
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Sep 2012 21:44 Edited at: 4th Sep 2012 21:45
@Silverman
Oh of course! I forgot it is comparing against the selected value, so I was checking for FALSE values, that's why everything was inverted. It just happens that I'd already compensated for the "w" and "s" being reversed. Thanks.

Now here it's all straightened out (including your spelling of "boolean" ):


Shh... you're pretty.

Login to post a reply

Server time is: 2020-08-05 03:39:35
Your offset time is: 2020-08-05 03:39:35