|
Post by alwichita2 on Jan 22, 2023 12:24:46 GMT -5
Hi Guys ! Is there a limit to the number of variables a program can have ? Is there a limit to the number of lines of code a program can have ? I have a fairly large program (35k lines of code, hundreds of sprites, hundreds subroutines, and countless variables) and I'm having some weird things happen all of a sudden... Although I am using old style branch label subroutines ie. gosub [name] /return, some global variables are no longer being passed to a subroutine. To be safe I declared them as global but they still don't get passed to the subroutine. I'll be doing some analysis and remove 99 % of the code and keep the subroutine and see if it still has issues, but in the meantime I thought I ask about any coding limits Thanks Al
|
|
|
Post by Rod on Jan 22, 2023 13:24:07 GMT -5
No limits are not usually an issue. But you may have used lots of graphic resource. We can only help if you give us a clue what the error.log states.
It is very easy to program simple errors that appear complex.
|
|
|
Post by alwichita2 on Jan 22, 2023 16:51:04 GMT -5
Thanks Rod ! There are no compile or execution errors other than a previously defined variable becomes 0, (as if not a global) ie. x=99 becomes 0 but with branch label subroutines ie. gosub [name] /return, Ive never had to define any variables as global, but I defined them as global anyway and still no effect. Not the actual code but it's virtually what's happening. Yes I have checked and it doesn't get reset anywhere, also changed variable names, etc. global lp, xlp for lp=1 to 40 print lp next xlp=lp gosub [xyz] end [xyz] print x, xlp ' both = '0' return I'll keep digging since I didn't hit any limits, and yes I'm sure its gonna be simple once I find it. Thanks Al
|
|
|
Post by Brandon Parker on Jan 22, 2023 16:53:42 GMT -5
Are you "passing" Global variables into actual subroutines (i.e. named Subroutines and not [labels]). You should not have any actual subroutine input parameter names that are the same as Global variables. There is a known issue with doing that...
If you are not using named Subroutines/Functions, variables are visible throughout the program and there is no need for Global variables. If you do not have any named Subroutines/Functions, it is most likely going to be the execution of some other section of code that is changing things and therefore a logical program flow issue.
I received the following from your example. This is what I would expect...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 0 41
{:0)
Brandon Parker
|
|
|
Post by alwichita2 on Jan 22, 2023 23:06:58 GMT -5
Thanks Guys ! I really didn't think that there were any limits to the # of variables or lines of code, I just wanted to make sure, as there is currently no explanation for above behavior (not yet) ! I'm using branch label subroutines with returns. ie. gosub [xyz] with a return. (and not using variables with the same name as branch labels) I have never had to declare variables as global (but I did, just to check, and it didn't fix it) (I also tried several other things including creating new variable names (with values set) to ensure they were not reset anywhere, all =0 ). I have a work-around in place, I just re-load the data from a file into my sub, it ain't pretty but it works, for now. I'll continue to troubleshoot this issue in the near future, especially if it continues in any other new sub-routines, (not the biggest fish to fry right now). If it creeps up again, or I truly fix the problem, or get more info., I'll keep you posted. Thanks a bunch ! Al
|
|
|
Post by Rod on Jan 23, 2023 2:26:55 GMT -5
It’s an understanding issue. Gosub is not actually a subroutine, it is a simple redirection to a [branch] label in the main code. It is there for backwards compatibility with older basics. A real subroutine or function needs a sub or function defined with sub xyz(a,b,c) thrn end sub or function xyx(a,b,c) end function.
Only when you create those types of subroutine or function do globals come into play and only then do local variables get created. It’s all well enough covered in the help file and Carls book.
|
|
|
Post by tsh73 on Jan 23, 2023 3:18:12 GMT -5
Hello Al As was said, with only gosub/return all variables are visible in all parts of the program and all variables are global So the only reason is indeed assignment (or error in variable name. Unused variable is "0" in BASIC, and "x" and "X" is different variables in Liberty BASIC. Did you notice "x" in your example is unassigned variable? )
Second "gotcha" is jumps if LB program has jumps (GOTO) out of FOR / WHILE / DO loops, it starts to misbehave (end of loop operator could in fact pass program flow to different place) It is particular LB quirck, and in the help it is said to use EXIT FOR / EXIT WHILE/ EXIT DO. This way, control flow works as expected.
|
|
|
Post by Rod on Jan 23, 2023 4:54:54 GMT -5
global gX,gY gX=10 gY=10
for i=1 to 40 call xyz,i next
sub xyz x print x,y,gX,gY 'x is i passed to the sub 'y is a new variable specific to the sub 'gX and gY are simply global variables 'dont pass globals to subs or functions 'simply use then inside the sub. end sub
|
|
|
Post by alwichita2 on Jan 23, 2023 11:38:55 GMT -5
Thanks Guys ! Got it ! This software has been in development for years now (software team of 1), ha ! In future programs, I'll be using defined subs and functions rather than branch label subs. The software is for a homemade dart board. Here's a YouTube link if you want to see it ! youtu.be/uXccOxXJBPoThanks ! Al
|
|