Using custom properties in calculations
Posted: Mon Jun 03, 2013 10:26 am
Hey there,
I'm an experienced developer in other languages and currently trying to learn some basic LiveCode, as I'm planning to use it in a programming course for non-coders
Now, I do have some serious problems with variables and scopes in LiveCode not at all behaving like I would expect.
I declare a few custom property of an image like this:
I call the function manually at the moment as it is not called automatically when the program starts, for some reason.
Now in a function of the same image, I want to use those properties:
It doesn't even enter the switch! The command it is in is definitely called though, but the switch is skipped.
And when I try to "answer" (btw. LiveCode really needs a console for tracing stuff like that without popups) any of the three custom properties directly after I initialize them, I only get the name of the properties and not a number.
What's going on here?
Would I be better off using local variables for this? Tbh. I don't really get the difference between local variables and custom properties. The latter does not need to be declared in an extra step, it seems.
I'm an experienced developer in other languages and currently trying to learn some basic LiveCode, as I'm planning to use it in a programming course for non-coders

Now, I do have some serious problems with variables and scopes in LiveCode not at all behaving like I would expect.
I declare a few custom property of an image like this:
Code: Select all
on newImage
set the distance of me to 4
set the initialWidth of me to width of me
set the initialHeight of me to height of me
end newImage
Now in a function of the same image, I want to use those properties:
Code: Select all
switch distance of me
case 4
set width of me to 0.25 * initialWidth of me
set height of me to 0.25 * initialHeight of me
break
.....
end switch
And when I try to "answer" (btw. LiveCode really needs a console for tracing stuff like that without popups) any of the three custom properties directly after I initialize them, I only get the name of the properties and not a number.
Code: Select all
answer distance of me -- yields "distance"
answer initialWidth of me -- yields "initialWidth"
Would I be better off using local variables for this? Tbh. I don't really get the difference between local variables and custom properties. The latter does not need to be declared in an extra step, it seems.