how to get openStack to execute

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ninetrees
Posts: 7
Joined: Thu Apr 22, 2010 6:54 am

how to get openStack to execute

Post by ninetrees » Thu Apr 22, 2010 7:28 am

This relates to mar 10 post "Declaring global variables/functions - use in many scripts"
I am having the same experience: my globals aren't initializing, openstack handler doesn't execute.
I have one stack with one card, most scripts are in stack script
A series of global variables are the very first lines. My globals don't seem to work. Well, they work in stack script, but not in a btn script. I've resorted to using fields for now.

My basic problem may be: how to "run" a stack?
What I do is edit a script. Then click Compile btn.
Then click the tool palette
Then click the Arrow key.
-- This does not execute openstack (on Mac or Win XP)
Is there a better way to switch from edit to run? Is there a way to avoid having the stack disappear? It doesn't always, but I don't know what makes it stay put sometimes. Here's test code

Code: Select all

global gTEST

on openStack
    put 1 into gTEST
    put "openstack has run... " & gTEST
    checkglobal
end openStack

on checkglobal
    put gTEST after msg
end checkglobal
if I type openstack in msg, I get expected result: openstack has run... 11. However, in the btn's mouseUp script, the variable is not global.

Code: Select all

on mouseUp
    put     "***" && gTEST 
end mouseUp
--This prints *** gTEST, even if I've executed openstack manually.
--What am I missing ?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: how to get openStack to execute

Post by jmburnod » Thu Apr 22, 2010 8:28 am

Hi Ninetrees,

you must declare the global in the btn script

Code: Select all

    
on mouseUp
   global gTEST
   put     "***" && gTEST
end mouseUp
Best

Jean-Marc
https://alternatic.ch

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: how to get openStack to execute

Post by Regulae » Thu Apr 22, 2010 8:33 am

As I understand it, the problem you are encountering is that you are creating global variables in the openStack handler of a stack script, and you’ve checked that the globals are being created when you run openStack (with your checkGlobal test), but other objects, like your button, act as if the globals don’t exist. You need to “tell” your button that the global exists, with:

Code: Select all

global gTEST

on mouseUp
   put "***" && gTEST 
end mouseUp
... in the button script. This way the global gTEST is available for use in any handler in the button’s script. If instead you use:

Code: Select all

on mouseUp
   global gTEST
   put "***" && gTEST 
end mouseUp
... the global gTEST is available only in the mouseUp handler. This is how the User Guide explains it:
Important: You must also use the global command at the start of a handler to make
an existing global variable available to a handler. While a global variable can be used by
any handler, you must do this in any handler you are going to use it in. If you don't
declare a global variable before using it, the handler will not take the global variable's
existence into account, and will simply create a local variable with the same name.
That’s what is happening in your button at the moment- without the line:

Code: Select all

global gTEST
... in the button script, Rev is creating a local variable gTEST instead, and that’s what you are seeing in the message box. I hope this helps, but please ask further if it is not clear, or misses the problem.
(I have just seen that Jean-Marc has given essentially the same advice)

ninetrees
Posts: 7
Joined: Thu Apr 22, 2010 6:54 am

Re: how to get openStack to execute

Post by ninetrees » Thu Apr 22, 2010 3:51 pm

It's been quite a while since I wrote in HT and Lingo. I forgot about the need to re-state the global. Thanks.

Post Reply