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