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!
on mouseUp
local server
answer file "What is the server path?"
put it into serverLocation
end mouseUp
Now I want this button, which i called start to run the server.exe by referring to the serverLocation container and i want my serverLocation container info to be put where i PUT IWANTMYVARIABLEHERE. This is so it can run the .exe file.
local serverLocationTwo
put serverLocation into serverLaunch
put serverLaunch into variableserver
put "start '' 'IWANTMYVARIABLEHERE'" into myShell
replace "'" with quote in myShell
get shell(myShell)
I am a complete noob, today is my first day actually trying to write code. So please help I dont know whats wrong I just know its wrong but dont know how to fix it. Please help!
-Thanks
Last edited by Alex_CTZ on Thu Apr 17, 2014 1:02 am, edited 1 time in total.
on mouseUp
local serverLocationTwo
put serverLocation into serverLaunch
put serverLaunch into variableserver
put "start " & variableserver into myShell
replace "'" with quote in myShell
get shell(myShell)
end mouseUp
on mouseUp
local serverLocationTwo
put serverLocation into serverLaunch
put serverLaunch into variableserver
put "start " & variableserver into myShell
replace "'" with quote in myShell
get shell(myShell)
end mouseUp
cause it doesnt work
-Thanks
It says it cant find serverLocation, does that mean that the variable it on button 1 is not being stored?
I have not worked with the shell command, but I suspect you are making it harder than you need to. Look at "Launch URL" in the dictionary. I also believe that you are having a problem with variable persistence. I believe I know what the problem is, but I want to give you a chance to figure it out. I will give you two helpful hints. First the number 1 debugging tool for finding variable problems is this simple line answer myVariableName. By putting it in your script at various locations you can find where the problem starts. The second clue, is to look up local and global in the dictionary.
good luck, and if you still cant figure it out come back for more hints.
magice wrote:I have not worked with the shell command, but I suspect you are making it harder than you need to. Look at "Launch URL" in the dictionary. I also believe that you are having a problem with variable persistence. I believe I know what the problem is, but I want to give you a chance to figure it out. I will give you two helpful hints. First the number 1 debugging tool for finding variable problems is this simple line answer myVariableName. By putting it in your script at various locations you can find where the problem starts. The second clue, is to look up local and global in the dictionary.
good luck, and if you still cant figure it out come back for more hints.
The reason i didnt use launch url was because I want to give this to my friends, but I couldnt find out how to make a certain user a variable to find the file automatically, so my second thought was for them to define a location, save it in a container and put it as a variable in the shell.
Thanks for the help, i will look into what you said, thanks so much for helping me learn rather than just giving me the answer
Alex_CTZ wrote:
The reason i didnt use launch url was because I want to give this to my friends, but I couldnt find out how to make a certain user a variable to find the file automatically, so my second thought was for them to define a location, save it in a container and put it as a variable in the shell.
Thanks for the help, i will look into what you said, thanks so much for helping me learn rather than just giving me the answer
-Thanks again
launch url can use a location in a variable as well.
Alex_CTZ wrote:
The reason i didnt use launch url was because I want to give this to my friends, but I couldnt find out how to make a certain user a variable to find the file automatically, so my second thought was for them to define a location, save it in a container and put it as a variable in the shell.
Thanks for the help, i will look into what you said, thanks so much for helping me learn rather than just giving me the answer
-Thanks again
launch url can use a location in a variable as well.
on mouseUp
put serverLocation into variableserver
put "start " & variableserver into myShell
replace "'" with quote in myShell
get shell(myShell)
end mouseUp
I realized the local was unnecessary, but it still says it cant find the serverLocation container variable.
on mouseUp
local server
answer file "What is the server path?"
put it into serverLocation
end mouseUp
The variable serverLocation will not persist outside of the first handler unless it is told to do so. There are several ways to do this. The simplest yet least recommended is the use of global variables, and declaring that variable global in each handler in which it is used. A better method is to declare it local outside of any handlers. In that way it becomes persistent to any handler within that script. Of course sometimes you have initiate scripts with buttons. For this reason I prefer to create a custom handler in the stack script and call that handler with the button instead of putting the script in the button itself E.G.
-- code in button
on mouseUp
doSomething
end mouseUp
--custom handler in stack script
on doSomething
--write button script here
end doSomething
in this way, you keep all your handlers in the stack script so all local variables declared outside of a handler persist.
another hint:
this note is in the dictionary under launch URL
Note : The urlToLaunch must be a standards-compliant URL, in particular file urls must be of the form file://<absolute path>.
on mouseUp
local server
answer file "What is the server path?"
put it into serverLocation
end mouseUp
The variable serverLocation will not persist outside of the first handler unless it is told to do so. There are several ways to do this. The simplest yet least recommended is the use of global variables, and declaring that variable global in each handler in which it is used. A better method is to declare it local outside of any handlers. In that way it becomes persistent to any handler within that script. Of course sometimes you have initiate scripts with buttons. For this reason I prefer to create a custom handler in the stack script and call that handler with the button instead of putting the script in the button itself E.G.
-- code in button
on mouseUp
doSomething
end mouseUp
--custom handler in stack script
on doSomething
--write button script here
end doSomething
in this way, you keep all your handlers in the stack script so all local variables declared outside of a handler persist.
another hint:
this note is in the dictionary under launch URL
Note : The urlToLaunch must be a standards-compliant URL, in particular file urls must be of the form file://<absolute path>.
on mouseUp
global serverLocation
put serverLocation into variableserver
put "start " & variableserver into myShell
replace "'" with quote in myShell
get shell(myShell)
end mouseUp
It works now Thank you so much, I now kind of understand the whole global and local variables
One more question,say I wanted to make a installer for something. How would I include a file so it could be put on the computer when installed? Can this be done?
on mouseUp
global serverLocation
put serverLocation into variableserver
put "start " & variableserver into myShell
replace "'" with quote in myShell
get shell(myShell)
end mouseUp
It works now Thank you so much, I now kind of understand the whole global and local variables
One more question,say I wanted to make a installer for something. How would I include a file so it could be put on the computer when installed? Can this be done?
Good job. However, using globals is a bad habit to get into, especially when you get into larger projects. To answer your other question, look at the menu bar under file for "Import as a control"
your homework:
Do some searching on this forum. there are several threads on using custom properties to store variables. also play around with the script local variables by declaring them local outside of handlers.