Log in

View Full Version : PBasic Variable


Matt Reiland
14-01-2002, 15:20
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?

Thanks
Matt

Joe Johnson
14-01-2002, 15:41
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.

Bottom line:

Take pains to make sure your declarations match from program slot to programs slot.

Joe J.

Matt Reiland
15-01-2002, 08:55
Sounds lke one headache I could do without.

pbhack
15-01-2002, 13:04
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.

Brent
Programming Mentor
Hero 278

Joe Johnson
15-01-2002, 13:16
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.

Buyer beware!

Joe J.