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 / "Sprite must be greater than zero", and it should indeed be

Author
Message
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 2nd Jan 2012 01:48 Edited at: 2nd Jan 2012 01:52
I have a very weird bug, the code in question is very simple, and it should be fail safe.



The program quits and keep saying that sprite must be greater than zero at the line containing delete sprite clean_up I am very puzzled, the bug have been there before but went away, and now it is back???

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 2nd Jan 2012 02:04
Are you sure that's where it fails?
The reported lines are not uncommonly off from the actual point of error.
I would try slapping in some print's or similar in that loop so that you can see where, at what number, if it gets past the delete sprite statement, etc.


"Why do programmers get Halloween and Christmas mixed up?"
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 2nd Jan 2012 03:42
didn't fail with me
Virtual Nomad
Moderator
20
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 2nd Jan 2012 05:35 Edited at: 2nd Jan 2012 05:38
one dbpro coding habit i have struggled to break for a long time now is the use of boolean commands like sprite exist() the way you have here.

while the code examples in the help files associated with these commands, ie:

Quote: "if sprite exist(1) then print "Found a sprite""


should and do work (99.99% of the time), i believe it's a better habit to, instead, code:

Quote: "if sprite exist(1) =1 then print "Found a sprite""


...as, in my 1/2 dozen years of tinkering with dbpro, i've experienced similar, confounding errors (a mere 3-4 times) that were fixed by the "=1" addition.

i have no idea why (these things are magic to me), but it does seem to make a difference. it's probably a dbpro bug but since it shows itself so rarely, it doesn't really get talked about or addressed.

<shrugs> hope this helps (someone )

Virtual Nomad @ California, USA . DBPro V7.5
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 2nd Jan 2012 12:24
I tried adding the = 1, but it didn't help :-( Now I am running it in debug mode and it seems that it just keep looping that piece of code infinitely :-(

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 2nd Jan 2012 16:41
Quote: "Are you sure that's where it fails?
The reported lines are not uncommonly off from the actual point of error.
I would try slapping in some print's or similar in that loop so that you can see where, at what number, if it gets past the delete sprite statement, etc.
"

this.

How do you know that it's that piece of code that gets run infinitely? (or... you ARE running through it 60 times, are you sure you ran through it that many times?)

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 2nd Jan 2012 23:56
Quote: "The program quits and keep saying that sprite must be greater than zero at the line containing delete sprite clean_up I am very puzzled, the bug have been there before but went away, and now it is back???"


The error is probably somewhere above that line. The quick way is to rem that part off and run the program again to see if you still get the error (which it should if it's above that line).

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Jan 2012 11:37
I was always puzzled of the addition of =1... Shall adapt asap

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 3rd Jan 2012 22:12 Edited at: 3rd Jan 2012 22:16
There is nothing wrong with using an if statement without an equals sign; infact you will not find many code examples in the MSDN (Microsoft) documentation that check if a function or variable is true with an equals sign.

So as long as you know what you are doing, you should not run into trouble for not using an equals sign. Just keep in mind that zero values are false; and a non-zero value next to the NOT operator; is false.

Usually it is easier to read something like:

If GameIsReady

or

If IsEmpty( StringVariable$ )

Rather than

If GameIsReady = 1

or

If IsEmpty( StringVariable$ ) = 1

What you need to watch out for are expressions like this, where you are comparing integers:

If MouseClick() and ReturnKey()

What is wrong there? Do you see the mistake above?

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 4th Jan 2012 01:31 Edited at: 4th Jan 2012 01:32
Quote: "There is nothing wrong with using an if statement without an equals sign"


Same goes for next, you don't need anything after it. So 'next something' can just be 'next'.

Interestingly you can do stuff like this all over the place like functions for one, you can leave out the comma's in the syntax and just have spaces. Oddly though, you can't do this when using it.

Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 6th Jan 2012 20:58
I will check the code more thoroughly later, I have been having some real life issues for a while *sigh* who needs real life anyway, when the digital world can be as peaceful or as violent as you like

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 6th Jan 2012 22:32
Quote: " who needs real life anyway, when the digital world can be as peaceful or as violent as you like "


WORD!

Login to post a reply

Server time is: 2026-07-09 15:24:25
Your offset time is: 2026-07-09 15:24:25