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 Professional Discussion / AAARRRGGHHHH, bad IFs!!!

Author
Message
Khumba
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 6th Jul 2003 19:59
DBPro is making me angry!!!

This code won't work, it'll always fail:


But if I change it to this, it works perfectly!



Same thing with this:


I have to change it to:


I'm doing this from inside a function, and so far I've only had to change the code when the first variable in the IF is an array, but why is this happening????
Khumba
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 6th Jul 2003 20:02
Sorry, here are my specs:
DBPro version 4.1, DX9, Pentium III 933MHz, 256MB RAM, Win98 SE, GeForce 2 MX400
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 6th Jul 2003 22:45
I have had that, but it happens mostly when you get "cute" with the logic, best thing to do is spell it out nice and simple for the compiler and leave it to sort out the structure of the compiled code for it`self (IMO), it probably throws all that structure out the window when it compiles anyway, just wrap everything in brackets and pray (well?...works for me!)

Mentor.

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 7th Jul 2003 00:10
What is the array defined as ? Integer ? Byte ?

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!
Khumba
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 7th Jul 2003 00:44
It's an array, not a structure (I haven't touched structs in my prog), and it's defined like this:

dim pSel(100, 2) as word

Hey, is it possible that since it's declared at the beginning of the program (outside a function), the function can't see it? Does it need to be global?

"Lose your questions and you will find your answers" -D'ni Proverb
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 7th Jul 2003 00:58 Edited at: 7th Jul 2003 00:59
Try defining as :

(and make sure the values are initialised)

To save you the trouble of finding out what works (and what doesn't), with patch 4.1, I've done it for you :

dim pSel(100, 2) as byte:rem doesn't work
dim pSel(100, 2) as word:rem doesn't work
dim pSel(100, 2) as dword:rem does work
dim pSel(100, 2) as integer:rem does work
dim pSel(100, 2) as double integer:rem DOESN'T work! Very surprising!
dim pSel(100, 2) as float:rem does work
dim pSel(100, 2) as double float:rem does work
dim pSel(100, 2) as boolean:rem doesn't work - surprise, surprise!

REM Rest of code:
i=0
pSel(i,1)=0
if pSel(i, 1) = 0
pSel(i, 1) = id
pSel(i, 2) = p
print "Y":wait key
exit
endif
print "N":wait key
Seems to be a problem with various types of variables.
Have you e-mailed Lee about this ? If not, do so as quickly as possible, or even sooner.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jul 2003 02:20
A trick I've seen posted (but not tried) is to reverse the order of the comparison.

Instead of this:
if pSel(i,1)=0

Try this:
if 0=pSel(i,1)
ICERGB
23
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 8th Jul 2003 11:16 Edited at: 8th Jul 2003 11:55
heheh
how about this


because that is really strange...
you technical guys do it the hard way I think
Beta1
23
Years of Service
User Offline
Joined: 28th Dec 2002
Location:
Posted: 8th Jul 2003 14:29
Because that doesnt do the same thing. The original should check the if statement and if true change the values of the arrays then exit. Yours runs only if all the values are already set and if you read your code will only ever be true if id=0

Khumba
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 8th Jul 2003 20:06
Hey, I just realized, aren't all variables integer-type by default if you don't declare them? There might be some conflict in comparing an integer to a word... I'll try increasing the size of my array, just to see if it works; I don't really want my game to take up twice the memory. Not on a comp with DB right now so I can't test it, but I'll also try reversing the order of the parameters. Thx for all the help!

"Lose your questions and you will find your answers" -D'ni Proverb
Khumba
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 9th Jul 2003 00:08
Okay, changing the array sizes worked, and so did reversing the comparison, thx IanM and MrTAToad! Sorry, but I already tried wrapping everything in brackets . I'll still email Lee though.

"Lose your questions and you will find your answers" -D'ni Proverb

Login to post a reply

Server time is: 2026-07-18 07:30:47
Your offset time is: 2026-07-18 07:30:47