LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
put getLevel (theValue) into theLevel
function getLevel aValue
if aValue < 45 then
return 'low'
else if aValue > 55 then
return 'high'
else
return 'average'
end if
end getLevel
But when I try to concat the value returned to another string it includes the single quotes:
2. A string is everything in QUOTES, but this means DOUBLE quotes!
If you -> return 'a value in single quotes'
then the single quotes are seen by the engine as PART of the string you are returning!
Try yourself by: answer getlevel(10)
Addition:
If your returned values consists of more than one word, this will fail completely!
So double quotes are mandatory, if you want to return a string!
This will put FALSE into the message box, not what you might exspect
on mouseUp
put getLevel (10)
end mouseUp
function getLevel aValue
if aValue < 45 then
return 'low and high'
else if aValue > 55 then
return 'high and low'
else
return 'average to say the least'
end if
end getLevel
Looking at it from the other side, know that double quotes are "native" elements in LC. But there is a constant called "quote". So the way to create something like (32") is:
Related question--I have five buttons, and for the sake of simplicity I have named them "1", "2", "3", "4", and "5" because it's a rating system and I can just put the name of the btn into the fld. But when I reference them with a loop:
repeat with i = 1 to 5
set the icon of btn i to the id of image (i & "-unchecked")
end repeat
LC treats the var i as a number, and refers to the btn as it's ordered on the page. How do I tell LC to treat the number as a string (as in i.toString() or String(i))?
The engine will refer to a NUMBER as a name of an object as its LAYER on the card:
So -> button "1" will be treated ad the FIRST button on the card, even if you have it crreated
on top of all other objects on the card.
Name your buttons something like "b1", "b2" etc. so you can still access them easily e.g. in a repeat loop.
set the icon of btn ("b" & i) to the id of image (i & "-unchecked")
This is standard practice, and your brain will "see" the concatenated string ("b" & i) in the same way you originally thought, but now LC's internal ordering of object references is out of play.
Really, you should never name any object with just a number. An object has various properties, one of which is the name, another of which is the number, and they reference the object differently. If you refer to an object such as field "1" this will not be interpreted as the name, but as field number 1, which may reference a completely different object. The way the engine works, I don't think there is any way that you can get a casting technique to override this interpretation.