View Full Version : PBasic Variable
01-14-2002, 03:20 PM
When breaking a PBasic program into 'slots' are you required to declare the same 26 variables in each slot or are you able to declare different variables? After I split my program up and looked at the memory map, 1 of the slots has a different # of bytes free than the rest because of a different variable declaration but the program didn't bomb out on verification?
Any knowledge of this one?
01-14-2002, 03:41 PM
What I am pretty sure about is that the physical RAM space is the same from slot to slot.
The problem is that your declarations really are just aliases for the the real RAM space.
If your declarations don't match, then the alias is pointing to a differen place in RAM.
This can really screw you up because a variable called Dog may actual be changing the variable you have been calling Cat in another program slot. This is a doubly bad event because Dog did not get the value you wanted AND Cat's value is trashed as well.
Take pains to make sure your declarations match from program slot to programs slot.
01-15-2002, 08:55 AM
Sounds lke one headache I could do without.
01-15-2002, 01:04 PM
I haven't done this, but this approach seems plausible...
1) Order variable declarations starting with global variables first.
2) For your own benefit, clearly mark the point of divergence where the variables (symbols) in each slot differ.
3) Consider all variables after the divergence to be "local"
4) In the "called" slot, make sure that you manually initialize the local vars.
01-15-2002, 01:16 PM
Yes, it is a bother. But...
If you are out of code space it is an acceptable way out compared to just taking features out of your robot control.
It can be managed. we had 3 slots last year: Initialization, Get data & Arm calcs, and Wheel calcs & output data.
It worked okay, but sometimes we made mistakes from program to program and caused some subtle errrors. Very tricky to find if you are not aware of the possible problems.
vBulletin® v3.6.4, Copyright ©2000-2013, Jelsoft Enterprises Ltd.