global variables not working in standalone...
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
global variables not working in standalone...
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.
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.
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: global variables not working in standalone...
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
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..."
Re: global variables not working in standalone...
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:
outside of any handlers, say at the bottom of the script?
Thanks for any suggestions or advice,
TJ.
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
Thanks for any suggestions or advice,
TJ.
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: global variables not working in standalone...
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)
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..."
Re: global variables not working in standalone...
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.
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.
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: global variables not working in standalone...
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
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..."
Re: global variables not working in standalone...
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.
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.
Re: global variables not working in standalone...
Hi TJ,
The global's are at top of the button script as well.
Simon
make sure thatHowever when one of the buttons is clicked the script for that button cannot seem to get the variable
Code: Select all
global gVeryImportantVariable, gVeryImportantVariable2
on mouseUp
answer gVeryImportantVariable
end mouseUp
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!