global variables not working in standalone...

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
tjo
Posts: 16
Joined: Wed Feb 12, 2014 12:08 am

global variables not working in standalone...

Post by tjo » Thu Feb 13, 2014 8:11 pm

I'm a noob to LiveCode. I did search the forum but couldn't find the answer...

I made my first LiveCode program. It works fine from within LiveCode, but when I create a Windows standalone it appears that the global variables are not working properly.

Is there something else I need to do when building the standalone to make these globals work under windows? And what about Android builds? This is something I was hoping to do as well.

Thanks for any advice or suggestions,

TJ.

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: global variables not working in standalone...

Post by dave.kilroy » Thu Feb 13, 2014 9:44 pm

Hi TJ and welcome to the forum

Have you defined your globals in each script you use them? E.g. have you got "global gVeryImportantVariable" in each script? Every single card and group script where you use them? I like to put all these declarations together at the top of the script (outside any handlers). Another thing that could get in the way of them working is if you have a local variable in a handler of the same name.

Those are the most obvious things I can think of for now, maybe others will pile in with their suggestions.

Dave
"...this is not the code you are looking for..."

tjo
Posts: 16
Joined: Wed Feb 12, 2014 12:08 am

Re: global variables not working in standalone...

Post by tjo » Thu Feb 13, 2014 10:20 pm

Hi Dave,

Thanks for your suggestions. Yes, I do have "global gVeryImportantVariable, gVeryImportantVariable2" at the beginning of each script, outside of any handlers.

So far I have been using the variables "gVeryImportantVariable" and "gVeryImportantVariable2" in my script inside handlers and just declaring them global at the top of the script for each card or control.

Should I be using just VeryImportantVariable inside the handler(s) and then use something like:

Code: Select all

put VeryImportantVariable into gVeryImportantVariable
outside of any handlers, say at the bottom of the script?

Thanks for any suggestions or advice,

TJ.

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: global variables not working in standalone...

Post by dave.kilroy » Thu Feb 13, 2014 10:42 pm

Well it sounds like you are doing it right, declarations of a global are indeed outside handlers and at the top of the script is the best place for them.

One thing that occurs to me is similar but different spellings - it has certainly happened to me that I thought I was dealing with one variable when in fact I was dealing with several due to my bad spelling and/or fast typing. Maybe try copying one of your problem globals and pasting it over every other instance of it to check for conformity of spelling (you can use the search box inside the editor to help with this - if it isn't showing hit command+f or control+f)
"...this is not the code you are looking for..."

tjo
Posts: 16
Joined: Wed Feb 12, 2014 12:08 am

Re: global variables not working in standalone...

Post by tjo » Fri Feb 14, 2014 12:11 am

OK, I will double check the variables. I also have an array that I have made global. Not sure if this could be causing a problem?

The strange thing is that it works fine when I run it inside LIveCode, but the Windows standalone build will not work.

I will keep trying, any further suggestions are appreciated.

TJ.

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: global variables not working in standalone...

Post by dave.kilroy » Fri Feb 14, 2014 12:20 am

Arrays as global variables should be no problem.

OK if things are working in the IDE but not standalones then that gives us a bit of a clue as to what is going on. For example you can't save anything to an executable...

I suggest you write down EXACTLY the problem is and what you have done to investigate - often just doing that can lead you to uncover the bug...

Good luck!

Dave
"...this is not the code you are looking for..."

tjo
Posts: 16
Joined: Wed Feb 12, 2014 12:08 am

Re: global variables not working in standalone...

Post by tjo » Fri Feb 14, 2014 5:01 am

Hi Dave,

Thanks for your reply. I added a scrolling text field to dump some of the variables in question into so I can see whats going on when I run the .exe.

My project requires that an array be created, and then the array and a few variables must be passed from one control or card to another for things to work.

I can see that the array and variables are being populated in the .exe when it is first run. However when one of the buttons is clicked the script for that button cannot seem to get the variable from the previous card or control. This is why I suspect it has something to do with global variables, as the variables are populated when the program is first run, but not passed to other cards or controls as various buttons are clicked.

Not sure if this helps to identify the problem at all.

Thanks again for any advice,

TJ.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: global variables not working in standalone...

Post by Simon » Fri Feb 14, 2014 6:56 am

Hi TJ,
However when one of the buttons is clicked the script for that button cannot seem to get the variable
make sure that

Code: Select all

global gVeryImportantVariable, gVeryImportantVariable2
on mouseUp
answer gVeryImportantVariable
end mouseUp 
The global's are at top of the button script as well.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply