I'm not understanding the Exists function
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
I'm not understanding the Exists function
exists(img "ncImg" of card "NonC")
if it is true then
delete img "ncImg"
end if
I get this error before it even gets to the if/then
button "Close": execution error at line 3 (Chunk: no such object), char 1
if it is true then
delete img "ncImg"
end if
I get this error before it even gets to the if/then
button "Close": execution error at line 3 (Chunk: no such object), char 1
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: I'm not understanding the Exists function
try this:
--Sefro
EDIT: As far as I understand it, the exists() function will return true or false, the engine has no idea what to do with this information. In addition to the first example, you could also:
or
Code: Select all
if exists(img "ncImg" of card "NonC")then
delete img "ncImg"
end if
EDIT: As far as I understand it, the exists() function will return true or false, the engine has no idea what to do with this information. In addition to the first example, you could also:
Code: Select all
put exists(img "ncImg" of card "NonC") into MyVar
if MyVar is true then
delete img "ncImg"
end if
Code: Select all
get exists(img "ncImg" of card "NonC")
if it is true then
delete img "ncImg"
end if)
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: I'm not understanding the Exists function
Hi.
What sefroJones said. But do you see what you did wrong in the beginning? You did not "do" anything with the function. You thought that it would go into the local variable "it", but never put it there. In fact, your line of code is only a fragment, since the engine could not understand what you intended, and reported so.
No different than if you asked:
"loc(field 1}"
Instead of, say, "answer loc (fld )" or "get loc (fld 1)"
Craig Newman
What sefroJones said. But do you see what you did wrong in the beginning? You did not "do" anything with the function. You thought that it would go into the local variable "it", but never put it there. In fact, your line of code is only a fragment, since the engine could not understand what you intended, and reported so.
No different than if you asked:
"loc(field 1}"
Instead of, say, "answer loc (fld )" or "get loc (fld 1)"
Craig Newman
Re: I'm not understanding the Exists function
Thank you guys, great help. I think maybe the dictionary on this one is a little too vague for my understanding at the least.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här
Re: I'm not understanding the Exists function
Hi DavJans,
rule of thumb: A function always needs to be GET or PUT... INTO...:
A handler/command can "stand alone":
Best
Klaus
rule of thumb: A function always needs to be GET or PUT... INTO...:
Code: Select all
on mouseup
put MyFunction() into myVar
put tVar into fld X
end mouseup
Code: Select all
on mouseup
aHandler
end mouseup
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: I'm not understanding the Exists function
Unlike C, Java, JavaScript, and some others, LiveCode has a distinction between commands and functions, similar to Pascal, SmallTalk, and a few other languages.
In LiveCode, every statement that isn't a control structure ("if", "else", "repeat", etc.) begins with a command.
Comnands perform actions, and are usually verbs ("get", "put", etc.), and they often operate on values.
Functions are sources of values, along with string literals, variables, or the values returned from querying properties. All sources of value will occur within the statement after the command operating on them.
I like to think of functions as placeholders, distinguished by their parentheses as though reminding us that something will be returned and put in that place.
As a simple example, here "AddTwoRandomNumbers" is the command, and "RandomNumber" is a function that returns a value for the command to operate on:
That example is so simple it's almost silly (you could more easily just call the random function within the command), but hopefully it helps illustrate the distinction between commands and functions in LiveCode.
In LiveCode, every statement that isn't a control structure ("if", "else", "repeat", etc.) begins with a command.
Comnands perform actions, and are usually verbs ("get", "put", etc.), and they often operate on values.
Functions are sources of values, along with string literals, variables, or the values returned from querying properties. All sources of value will occur within the statement after the command operating on them.
I like to think of functions as placeholders, distinguished by their parentheses as though reminding us that something will be returned and put in that place.
As a simple example, here "AddTwoRandomNumbers" is the command, and "RandomNumber" is a function that returns a value for the command to operate on:
Code: Select all
on AddTwoRandomNumbers
put RandomNumber() + RandomNumber() into fld "Display"
end AddTwoRandomNumbers
function RandomNumber
return random(100)
end RandomNumber
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: I'm not understanding the Exists function
Even if you do this:
you could still get your original error
Try:
Code: Select all
if exists(img "ncImg" of card "NonC") then
delete img "ncImg"
end if
if you are not currently on card "NonC" and there is no image 'ncImg" on the current card.execution error ... (Chunk: no such object),
Try:
Code: Select all
if exists(img "ncImg" of card "NonC") then
delete img "ncImg" of card "NonC"
end if
Re: I'm not understanding the Exists function
You guys are all awesome, I learned a lot from this question.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här