I have a question , I noticed that when I use a variable to count the score of clicks of different objects . The value of the score that uses variable whether it was a global or a local variable maintain its value of the score that has reached and continues to count from that point even when I close and re-open the app and I reset the variable value to 0 with code (put 0 into _gScorePlayer ) for example when a user reaches score 15 and closes the app , next time the score continues from 15 and so on
I am a beginner in livecode
Thanks fro your continues help and support guys :)
you can use the put command to clear the variable and the delete command to remove it from memory.
check the LiveCode dictionary
delete variable
Example
delete local tVar [1]
By default, declaring variables is optional in LiveCode.* Persistence of variable values is determined by whether the variable is declared outside of a handler or not. When a variable is only declared or used inside a handler, the variable is always temporary and its value is only valid while the handler is running.
The value of variables declared as local or global outside of a handler will persist between instances of the handler being run. However, the value of such variables will not persist between launches of LiveCode. That is if you quit LiveCode and launch it again, the values of the declared variables will be lost. However, if you only close the stack without quitting LiveCode, the stack remains in memory (by default) and the values of declared variables remain intact.
If you want to ensure that the variable is reset when the stack is reopened, do this for declared globals in the stack script:
global gScorePlayer
on openStack
put empty into gScorePlayer
# OR
put 0 into gScorePlayer
end open stack
To initialize local variables you do something similar in the script where the variable is used. For example, if you are using a local variable in a card script, you can do this in the card script:
local sMyLocalVar
on openCard
put empty into sMyLocalVar # or put 0 into sMyLocalVar
end openCard
*See the explicitVariables property in the Dictionary for more information about declaring variables.
The way I use to clean the content of a variable is:
delete variable VariableName
Related
I am basically trying to save to data/${EPOCH_TIME}:
begin_unix_time: "J"$first system "date +%s"
\t:1 save `data/"string"$"begin_unix_time"
I am expecting it to save to data/1578377178
You do not need to cast first system "date +%s" to a long in this case, since you want to attach one string to another. Instead you can use
begin_unix_time:first system "date +%s"
to store the string of numbers:
q)begin_unix_time
"1578377547"
q)`$"data/",begin_unix_time
`data/1578377547
Here you use the comma , to join one string to another, then using cast `$ to convert the string to a symbol.
The keyword save is saving global data to a file. Given your filepath, it looks like youre trying to save down a global variable named 1578377547, and kdb can not handle variable names being purely numbers.
You might want to try saving a variable named a1578377547 instead, for example. This would change the above line to
q)`$"data/a",begin_unix_time
`data/a1578377547
and your save would work correctly, given that the global variable a1578377547 exists. Because you are sourcing the date down to the second from linux directly in the line you are saving a variable down to, this will likely not work, due to time constantly changing!
Also note that the timer system command will repeat it the execution n times (as in \t:n), meaning that the same variable will save down mutliple times given the second does not change. The time will also likely change for large n and you wont have anything assigned to the global variable you are trying to save should the second change.
I have an input file where some variables are defined. For each iteration in a loop, I would like to read the file, update the values of some of the variables, then run calculations.
I have an input file called input.jl with
myval=1
Then I have a file myscript.jl with the following commands
for i=1:2
include("input.jl")
println(myval)
myval=2
end
If I run the file (julia myscript.jl), I get an error that myval is not defined. If I comment out the third or fourth lines, then it runs with no problem. If I remove the for loop, the three lines run with no problem. How can I read myval from input.jl, use it, then update its value during each iteration of the loop?
Unfortunately, it seems that the include function executes things at global scope, and then continues from where it left off. So if you're trying to dynamically include new variables into local scope, this is not the way to do it.
You can either introduce the variable at global scope first so that the function has access to it, and therefore the assignment will work (but, be aware that the variable will be updated at the global scope).
or
you can cheat by wrapping your input file into a module first. You still need to call the variable by its name, and you will get warnings about updating the module, but this way you can update your local variable dynamically at least, without needing that variable at global scope:
# in input.jl
module Input
myval = 1;
end
# in your main file
for i=1:2
include("input.jl")
myval = Input.myval;
println(myval)
myval=2
end
or
you could add a separate process and offload the calculation to its global scope, and retrieve it to your current process locally, e.g.
# in file input.jl
myval = 1
# in main file
addprocs(1);
for i=1:2
myval = remotecall_fetch(() -> (global myval; include("input.jl"); myval), 2);
println(myval)
myval=2
end
I have a code script in a stack that runs on KeyboardActivated. The codes needs the name of the active control. I can get that by adding on openfield code for each control that generate a KeyboardActivated. But is would be much easier of there was a way for the stack to know which control is active. Is that possible?
You could use a front script. To designate a script a front script, use this syntax
insert the script of control x into front
You can use an openField handler:
global gLastOpenedField
on openField
put the long id of the target into gLastOpenedField
pass openField
end openField
The front script will catch all openField handlers and store the long id of the target into a global variable. Don't forget to pass the openField message on to the next level!
That is what Mark meant. If you trap the "openField" message in a frontScript, and do not pass it, it will be processed, but then discarded. The "pass" command does just that, sends it along the hierarchy.
You can think about this the other way around. If there were no "openField" handler in "front" at all, the message would pass normally through that hierarchy level without being trapped, (this is the normal way) and would then be available to be caught by that field you mentioned.
All handlers work this way. When a message is trapped, it is processed and discarded, unless explicitly passed. The only other way around this trashing is to use the "send" or "dispatch" commands, which can "pass" the message to any object, regardless of its place in the hierarchy.
Did you try using "the target"? I never use front/back scripts and always get things sorted that way. ie:
on KeyboardActivated
put [short] name of the target into MyVar
-- do your stuff
Bash question!
so I have n arguments, and for each argument I'd like to to do a for loop and assign variables to hold characteristics of each argument. for example I have a script that runs in a continuous while loop and looks at user activity in my network... this is a simple outline of what my problems are:
while true
for argument
do
# build an array to hold times
"$user"_times =()
# set a boolean value
"$user"_boolean=true
if [ ""$user"_boolean" = true ]
then
echo $user logged on
"$user"_times+=( timestamp )
fi
done
done
exit 0
the real script will look at user activity, update the boolean based on certain user behavior, and log some user activity info in the array- but I'm trying to get this to work so I can add the easy meat. what should the syntax be? I'm having a hard time making the variables work.
Since bash doesn't support hash/maps, I'd consider perl/python to store user activity against their hash id. You also have access to vectors for variable sized activity details, eg a hash of userid's containing a vector of activities.
Python script to list users and groups
I am trying to get someone else's bash that sets various variables depending upon where a system comes up (z/VM Disaster Recovery provision). It is written so that it dots in a file containing variables with assigned values like this:
. /tmp/listofvars
IP=${SITE}IP
The value of the variable "$SITE" is set higher in the script, the result should be one of two things, either the value of the variable "$PRIP" for the production IP subnet value held in the variable list or the value of the variable "$DRIP" for the disaster recovery subnet value also held in the variable list that gets dotted in.
What actually happens is that the value of the $SITE variable gets concatenated to the string "IP" so the result is either "PRIP or "DRIP" depending on where I run the script. What I want is for the value of the $PRIP or $DRIP rather than the value of $SITE with the string 'IP' concatenated to it.
You can use variable reference as:
echo "${!IP}"
# will print value of $PRIP if $IP=PRIP