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 / Bug: problem with FOR and Next statements

Author
Message
Serge Adjo
19
Years of Service
User Offline
Joined: 3rd Aug 2006
Location:
Posted: 30th Apr 2010 23:37
Hi there, I wrote a long program and I have noticed an important bug that comes from DarkBasic pro: I believe it concern the FOR Next statements because in my program there is this code:


(the important command in this code is 'HIDE OBJECT Z+0')

the aim of the above code is to make the enemies ( 3 eyeballs) flash on and off: they should appear and disapear alternately BUT in fact, when I run the program there is only one of the 3 eyeballs that flash on and off ! and yet the FOR NEXT loop affect every eyeball in the scene !

I haven't tried to reproduce this error on smaller code.
here is the full program and attached to this post a zip file containing my program and all its media:


I think that FOR NEXT don't work properly, what do you think ? can you help me please ?

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 1st May 2010 00:17 Edited at: 1st May 2010 00:18

Restructure your code. Try this.

My signature is NOT a moderator plaything! Stop changing it!
gamerboots
17
Years of Service
User Offline
Joined: 8th Dec 2008
Location: USA
Posted: 1st May 2010 00:19
was the "step 3" intentional in the code in the first statement?


FOR Z = V_ENNEMISA_E TO V_ENNEMISZ_E-2 STEP 3

----------------
Gamerboots~
Serge Adjo
19
Years of Service
User Offline
Joined: 3rd Aug 2006
Location:
Posted: 1st May 2010 00:40
@Mobiius, I've tried but it still the same problem !

@gamer boots, yes it was intentional: this is because the eyeball is made of 3 Objects so I use 'STEP 3' to modify one of the 3 Object for each eyeball.

please try the attached files with your IDE to see the problem.

gamerboots
17
Years of Service
User Offline
Joined: 8th Dec 2008
Location: USA
Posted: 1st May 2010 00:56 Edited at: 1st May 2010 01:00
I get a wierd compiler error when I try to compile it. what version of dbp did you compile it in ?

----------------
Gamerboots~
Serge Adjo
19
Years of Service
User Offline
Joined: 3rd Aug 2006
Location:
Posted: 1st May 2010 01:25
@gamer boots, the version is 7.4, I don't know what to do if you can't compile my program, maybe you should try the exe :
attached to that post is the 'exe' file, simply put it in the main folder : '_TIREUR D'ELITE II'

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 1st May 2010 01:41 Edited at: 1st May 2010 01:43
You are using the `Z` variable step 3 to check both the AI entity and the object to hide. Is that right? You say you have 3 objects per eyeball so you would increment only by 1 for checking each eyeball? What's the relationship between the eyeball (entity?) number and the object numbers?


edit: and why have Z+0? It serves no function.
I would add some variable tracing in to see exactly what numbers are being produced in the loop. Display your start value, end value and each increment of Z and if they all tie up you know the for-next loop is fine. (Which I'm betting it is!)
gamerboots
17
Years of Service
User Offline
Joined: 8th Dec 2008
Location: USA
Posted: 1st May 2010 11:33 Edited at: 1st May 2010 11:37
I thought it might be the step 3 as well but he said it was intentionally coded that way.
@Serge Adjo
when you compile it are you using array bounds checking ? if the error I am getting is correct then there is an array assignment out of bounds somewhere and you'll have do to the dreaded trace de-bugging or re-write that part. Perhaps you have a plug-in I dont ??

----------------
Gamerboots~
Serge Adjo
19
Years of Service
User Offline
Joined: 3rd Aug 2006
Location:
Posted: 1st May 2010 12:17
@gamer boots, I think I've figured out the compilation error you get: I'm using several plugins! :
-Sparky SC_Collision.dll
-DarkAI
-Enhancements.dll

@sladeiw I've tested every possibility but I can't find anything wrong in my code and it should work perfectly! it drives me sad...
explanations:
There are 3 objects per eyeball, the first one is for visibility, the second is for collision checking and the third is for transparency and FX special effects. There is also one DarkAI Entity per eyeball:
-eyeball #1 : DarkAI entity #1, objects #1, 2 & 3.
-eyeball #2 : DarkAI entity #4, objects #4, 5 & 6.
-eyeball #3 : DarkAI entity #7, objects #7, 8 & 9.
-etc... and so on...

so now I want to hide and show alternately every first object of the eyeballs. the simplest way is to use FOR NEXT STEP commands but it don't work: the only result I get is one object flashing and the other aren't flashing !

If I encounter the same kind of problem I will post in the 'bug report' board !

gamerboots
17
Years of Service
User Offline
Joined: 8th Dec 2008
Location: USA
Posted: 1st May 2010 13:11
thats the thing, from your point of view it should work perfectly, but doesn't. I think if you do a few nights of trace-debugging you might find the offending variable or part of the source that is not working the way its suppose to however, it could take a while to track it down so I suggest that it might be easier if you just make a new program of just the flashing eyes. Start with one set of eyes and instead of using variables use numbers. If it works you can add another set and see how that goes. Eventually you will want to replace the numbers with variables. This route would be far easier I think than actual trace-debugging but would also be far easier to debug as the source would be much smaller. If an actual bug in the for-next truly does exist it would definately be a good way to show it.

----------------
Gamerboots~
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 1st May 2010 13:19 Edited at: 1st May 2010 13:34
You are resetting the timer as soon as the first entity to flash matches, move the timer reset
outside the loop (After the NEXT Z)




edit: above wont work of course because it will reset timer everytime, this should work:



another edit!
If you want them to all flash independently and not all synchronized then you will need an array for V_TIR_ENNEMIS_E to keep a seperate timer for each entity.(And put the reset timer back inside the loop) Randomize the intial value of each timer ie. rnd(500) and they will each flash at different times.
Serge Adjo
19
Years of Service
User Offline
Joined: 3rd Aug 2006
Location:
Posted: 4th May 2010 15:12
@Sladeiw, moving the timer reset don't change the problem!

The problem I'm getting has another consequence: the 'life' variable, (which is printed at the top-right hand corner of the screen during the game), should decrement by 3 because there are 3 enemies firing at the player but currently the 'life' variable decrement by 1. Maybe the error isn't from DBP but from my code: can somebody try the attached file and then help ? below is the part of the code that don't work and the full program.


full program:

simply open the 'FullSourceDump.dba' file and read 10 lines from line 590 to 600. See what's wrong... Thanks for help

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 4th May 2010 16:55 Edited at: 4th May 2010 16:56
If I am reading your code right, then having the timer reset within the loop is never going to work, because the first matching condition "IF AI Entity Exist ( Z ) = 1" will reset the timer if the "IF TIMER() - V_TIR_ENNEMIS_E >= 500" condition is also true. Then on all the subsequent loops, the timer condition will never match because it has been reset.

You either have to have a single timer which triggers the whole loop to execute, or have individual timers for each entity.

Also, as mobiius said I think it would be a good idea to structure your code as he did because it makes it much more readable!
Serge Adjo
19
Years of Service
User Offline
Joined: 3rd Aug 2006
Location:
Posted: 4th May 2010 18:23
@sladeiw said:
Quote: "having the timer reset within the loop is never going to work, because the first matching condition "IF AI Entity Exist ( Z ) = 1" will reset the timer"

YES ! you are right, I didn't noticed this before you said it ! so there is no problem at all, because I did something wrong in my code and it just need to be fixed ! So now, let's use the corrected programme :

This code works. Thank you @sladeiw !

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 4th May 2010 22:07 Edited at: 4th May 2010 22:08
Np, glad it works although it still looks wrong to me! You're testing the timer on every loop, but resetting it on the last iteration. I don't understand why you can't test for the timer first?



In any case, glad it works
Serge Adjo
19
Years of Service
User Offline
Joined: 3rd Aug 2006
Location:
Posted: 17th May 2010 17:55
@sladeiw, actually the code that I've posted don't work,in my previous message...
So, I've tried yours and it works fine, thank you sladeiw !

Login to post a reply

Server time is: 2026-07-26 01:26:12
Your offset time is: 2026-07-26 01:26:12