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!
In other programming languages, we can declare a variable and immediately set an initial value. For instances we are setting the default app settings and we would do something like
-- VARIABLES
local defaultColor = "blue";
local defaultPath = "c:\my directory"
local defaultWidth = 100
local defaultHeight = 200
-- FUNCTIONS AND HANDLERS
on mouseup
answer "hello world
end mouseup
You probably want to use a "global" variable.
Most people here will tell you a "custom property" is the "right" way to go, but for a beginner I think "global" is easier to understand.
In your stack script
In LiveCode, there are a few types of "standard" (there are other special ones) variables. They may be declared outside of handlers, but cannot be populated outside of handlers:
1- A local variable, declared and loaded when it is created:
on mouseUp
put something into yourVariable -- declared and populated. available only within the handler
answer yourVariable
end mouseUp
2- A script local variable, declared generally at the top of the script but outside and above any handler that might use it:
local yourVariable
on mouseDown
put something into yourVariable -- declared above, populated here, available to all handlers in the script
end mouseDown
on mouseUp
answer yourVariable -- you will get the contents
end mouseUp
3- A global variable, declared anywhere, and available in any script in any stack in the current session:
global globVar
on mouseUp
put 6 into globVar -- now available in any handler in any script that declares it
end mouseUp