GLBasic forum

Main forum => GLBasic - en => Topic started by: UBERmonkeybot on 2015-Aug-05

Title: Debug isn't working inside FOREACH loops
Post by: UBERmonkeybot on 2015-Aug-05
Hi all,
I have just discovered that Debug isn't working inside FOREACH loops.


Is this normal? :|
Title: Re: Debug isn't working inside FOREACH loops
Post by: MrPlow on 2015-Aug-05
Please show code sample of loop
Title: Re: Debug isn't working inside FOREACH loops
Post by: spacefractal on 2015-Aug-05
you can alternative uses STDOUT or using BOUNDS() in the for. Its does pretty much the same.
Title: Re: Debug isn't working inside FOREACH loops
Post by: MrTAToad on 2015-Aug-06
Do you have debug mode on ?
Title: Re: Debug isn't working inside FOREACH loops
Post by: kanonet on 2015-Aug-06
Are you talking about debugging in general or about the command DEBUG? And like MrTAToad mentioned, you need to have debug mode enabled.
Title: Re: Debug isn't working inside FOREACH loops
Post by: UBERmonkeybot on 2015-Aug-06
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
Title: Re: Debug isn't working inside FOREACH loops
Post by: kanonet on 2015-Aug-06
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.
Title: Re: Debug isn't working inside FOREACH loops
Post by: UBERmonkeybot on 2015-Aug-06
Hey Thanks Kanonet that's a really great tip.
Title: Re: Debug isn't working inside FOREACH loops
Post by: UBERmonkeybot on 2015-Aug-08
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.
Title: Re: Debug isn't working inside FOREACH loops
Post by: MrTAToad on 2015-Aug-08
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.
Title: Re: Debug isn't working inside FOREACH loops
Post by: UBERmonkeybot on 2015-Aug-08
OK.

Thanks.
Title: Re: Debug isn't working inside FOREACH loops
Post by: kanonet on 2015-Aug-08
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.