Debug isn't working inside FOREACH loops

Previous topic - Next topic

UBERmonkeybot

Hi all,
I have just discovered that Debug isn't working inside FOREACH loops.


Is this normal? :|

MrPlow

Please show code sample of loop
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

spacefractal

you can alternative uses STDOUT or using BOUNDS() in the for. Its does pretty much the same.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad


kanonet

Are you talking about debugging in general or about the command DEBUG? And like MrTAToad mentioned, you need to have debug mode enabled.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

UBERmonkeybot

#5
Yes debug is on.

I am stepping through the FOREACH loop and trying to output the content of an array of types
If you notice before and after the loop there are   debug commands,these work fine but anything inside the FOREACH is not output.  e.g.  TEST

Code (glbasic) Select




FUNCTION plotEnemy:
//DEBUG "\nenemy"
// These values are defined LOCAL:
//LOCAL y=0
LOCAL q,x#,y#
        DEBUG "\n PRE- GIMMER"


FOREACH q IN Enemy[]

x#=q.x#
y#=q.y#
DEBUG "\n   Enemy[q].x" +q.x#

        DEBUG "\nTEST"
        // q.x#=q.x#+q.xv#
// q.y#=q.y#+q.yv#
DRAWRECT x#,y#,50,50,0x666666

                DEBUG "\n GIMMER"
//PRINT  q.y#
//PRINT  q.x#
//INC y
NEXT

//
// DEBUG "\n  x "//+Enemy[0].x#,600,100
// DEBUG "\n  y "+Enemy[0].y#
////debug "test"


ENDFUNCTION // PLOTENEMY

kanonet

Cant confirm a bug here, works perfectly for me. Are you sure that your array does contain elements? Maybe position this before the FOREACH, if it displayes 0 then the bug is in your code:
Code (glbasic) Select
DEBUG "Elements in Array Enemy: " + Enemy.count + "\n"
BTW FOR and FOREACH do create their loop variable themself, so there is no need for you to define your variable q before the FOREACH loop.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

UBERmonkeybot

Hey Thanks Kanonet that's a really great tip.

UBERmonkeybot

Just out of interest Kanonet how did you know about the .count property i can't find any mention of it,I am a total Noob with GLB and am in discovery mode.

MrTAToad

Technically, BOUNDS should be used instead, in case the count variable name was changed, although the chances of it happening are low.

I believe Gernot mentioned it a fair while ago, but I cant find out where.

UBERmonkeybot


kanonet

MrT is right, the proper GLBasic way would be to use either BOUNDS or LEN. The .count works because of the C++ code that GLBasic gets converted to, when compiling. Since it is not official feature, its use is a tiny bit dangerous, since the underlaying C++ core may get changed at any time, which would break your code. I found out about this, simply by looking at the C++ code, which is always an interesting thing to do.

I like .count because its nicer looking and feels better - but I should not have recommended it to a newbie, BOUNDS and LEN are the way to go.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64