Defining global array?

I’m still new to xojo and I’m wondering how I can create a global variable/array?

I have a bunch of xojo scripts running at different intervals and I need them to communicate between themselves so they can get and set global values.

Script 1 runs, reads a probe from hardware and stores that in a global array.
Script 2 runs and needs to check the value that script 1 set earlier, so it knows if a relay needs to be turned on.

So I need to create a couple methods in my class set as the script context, and those need to get and set some global data that will live as long as the app is running via a global array so the scripts can read and write from it.

The script objects go out of scope as another script is starting, so I can’t store the data in the class set as the context as that will die when the new script object is instantiated.

Any help on how best to do this?

What about placing them in a module ?

Yeah that’s the thing, i create a new module, see what I can add to it… and I get constants and methods etc…, no variables.

I’m just not used to all this visual handholding :smiley:

But I think I got it sussed.

I found that I can create a property in a module and name the property with () at the end, like strMyProperty() and it becomes a property array of whatever datatype I set in the “type” field.

Autocomplete gave it away with offering append, pop etc…

I’m falling in love with autocomplete in Xojo, datatypes and controls are self documenting to a large degree.

Note if you define an array with () or (-1) you are creating a DYNAMIC array… and should use APPEND and INSERT to add elements
If you need/want a FIXED array make sure you define it with the required size inside the parends.

a() or a(-1) is dynamic
a(93) is static

Got it, thanks.

I defined a structure and threw what I needed in there (String/Value pair), then set that up as a static property array (100 is plenty since it’s just for script intercommunication), that way I can handle upper/lower bounds checks for the user so they can’t break anything, and I don’t need any elaborate error checking.

[quote=52225:@Dave S]a() or a(-1) is dynamic
a(93) is static[/quote]

This is incorrect. The property a(93) in a module is not automatically static/fixed, and the append/insert/remove commands will still function on the array. It simply creates a dynamic array with 93 empty/default values.

It’s better to use a class than a structure.

I usually reserve classes for something where I’d need multiple instances.

If you have an array of 100 of them, then you do have multiple instances. :slight_smile: The benefit to using a class is in this scenario is that you don’t need to worry about string length. Structures use fixed-length strings, which are often disadvantageous.

What I meant (In my clumsy ESL wording) was the declaration of the array would be in one place only so there’s not much reuse in that case.

But I guess for the ease of string length it’s a better option over a struct, I just stick a terminator in there when dealing with fixed length strings, old habits die hard :smiley: