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!
Syntax:
the value of expression
value(expression[,object])
You have two ways to invoke a in-built function in Livecode. The "normal" way with parenthesis or "the value of xxx". In the second case you have to use "the" and "of" otherwise the compiler does not know what you mean.
on mouseUp
put the value of "3+3" into field 1
put cr & value("3+3") after field 1
put cr & 3 + 3 after field 1
put 3 into tVar1
put 3 into tVar2
put cr & tVar1 + tVar2 after field 1
put cr & myAddingFunction(tVar1,tVar2) after field 1
put cr & myAddingFunctionWithErrorChecking(tVar1, tVar2) after field 1
put "oops" into tVar2
put cr & myAddingFunctionWithErrorChecking(tVar1, tVar2) after field 1
end mouseUp
function myAddingFunction param1, param2
return param1 + param2
end myAddingFunction
function myAddingFunctionWithErrorChecking param1, param2
if not (param1 is a number) or not(param2 is a number) then return "error, must be numbers"
return param1 + param2
end myAddingFunctionWithErrorChecking
Thank you very much jmburnod.
Now, I solved for my calculator, but is there a check or parse function that control if statement is correct?
I was used to work with Rebol language (very similar to LiveCode) and there was a try function that you could use this way:
...
try
do "put 3 into b"
## Catch possible error
catch errornum
## ERROR happened!
## Now do what you need in this case
answer "WRONG CODE!"
## Exit htis handler or do whatever you need
exit HANDLER_NAME
end try
## Success, cary on with your script...
...
returns TRUE since you force the evaluation before passing the parameter to the function isNumber. Without evaluation first isNumber "thinks" it is a string literal because of the quotes, see above.
why don't you take a look into the dictionary?
It ain't really THAT bad
...
Best
Klaus
Thank you Klaus!!! I searched try in the dictionary without finding it, but I found it in the User Guide! Yes!
I'll publish my scientific calculator very soon!
Thank you, thank you, thank you, thank you!
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Also, I'd avoid the "vaule" or "do" functions here. They both have some overhead because the engine needs to load the compiler every time either one is used, and LiveCode syntax makes them unnecessary most of the time. The examples Bernd gave that don't use "value" or "do" will work fine.
There are very few cases where scripts need those functions, the engine is pretty smart.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com