Page 1 of 1

Search Error Message

Posted: Sun Aug 12, 2018 8:37 pm
by kespears
I'm finishing a Card Database and I added a Search button with the following code:

on mouseUp
go to stack "Search" as palette
end mouseUp

When I press the Search button I get the following error:
Search LiveCode Error.png
The action stops here:

on openCard
put the number of this card && "of" && the number of cards of this stack into field "page"
end openCard

I appreciate any suggestions.

Re: Search Error Message

Posted: Sun Aug 12, 2018 9:38 pm
by quailcreek
Is stack "Search" a substack?
Where is your openCard script located?

Re: Search Error Message

Posted: Sun Aug 12, 2018 9:51 pm
by bogs
Yah, was going to say that code has a bit of a logic error maybe.

The way it looks (to me) is like you click on the search button, go to a separate stack named search, and when the card on that stack opens, your telling it to put the number of the card of the search stack "of" the cards of the search stack (I would assume there is only one card there for one thing, and the cards you actually want are in the main application stack).

What you would actually need/want is the number of the card you came from out of the number of cards in the main stack, I'm guessing.

If I am correct in that assumption, you could do something like this -

Code: Select all

// button code ...
on mouseUp
   set the cpropTarget of this stack to the number of this card
   go to stack "search" as palette
end mouseUp
Search stack open card code -

Code: Select all

on openCard
   put the cpropTarget of stack "frmMain" && "of" && the number of cards of stack "frmMain" into field "page"
end openCard
*Edit - this also assumes of course that you have a field on your search stack card that is named "page". If not, that is the object error.

*Edit 2 - maybe not, char 43 is "number'. hm.

Re: Search Error Message

Posted: Sun Aug 12, 2018 11:40 pm
by FourthWorld
Is field "page" in the palette or the topstack?

Re: Search Error Message

Posted: Mon Aug 13, 2018 2:43 am
by kespears
quailcreek, the “Search” is a button in the Main.Stack. Thanks.

bogs, The “openCard.....Pages” is in a field in the Main.stack as well. Its only function is to shop Page# of Pages. I will update my Scripts with your suggestions and give it a try. Thanks.

FourthWorld, the “page” is on the Main.Stack. Thanks

Keith

Re: Search Error Message

Posted: Mon Aug 13, 2018 3:45 am
by bogs
Hm. I don't think my script is going to help you overly much then, as I said, after reading your post I assumed that the field "page" was only on the search stack. It would certainly make more sense to have it on every card of the main stack, as I am guessing thats where the cards your cycling through are.

If that is the case, it would certainly be easier to just put an empty openCard handler on the search stack card and eliminate the field "page" from that stack setup altogether. That eliminates using the custom property I setup and reduces your code back to what it was.

*Edit - I found the program lesson your following, I'll take a look at it so that I might better help you out.

*Edit 2 - Ok, so if I'm right, this is a picture of what the app your working on looks like -
Image
Is that the app?

Re: Search Error Message

Posted: Mon Aug 13, 2018 5:05 am
by bogs
Actually it is much like I thought after I found (I think) the app article kespears is following.
You can make an app! wrote: Finally, go to the stack script for the Search stack and add an "on openCard" handler. It doesn’t need anything inside – this is just to stop our openCard script from the main stack from being run when this stack’s card opens.
So, I was right above - the field "page" isn't on the search stack (object error char 43), and from the last post -
bogs wrote:
Mon Aug 13, 2018 3:45 am
If that is the case, it would certainly be easier to just put an empty openCard handler on the search stack card and eliminate the field "page" from that stack setup altogether.
The article wasn't a bad one, you come out with a very simple but highly functional starting program, although it did contain mistakes (mainly the missing "go" when switching cards, but the article also said to drag an image object out and then never used it !? I of course used it for a backdrop :twisted: ).

Lc is easy, but proof reading a bit more when writing things is good too. Of course, an argument could be made that "... we need to find out what the level of problem solving skills are...", but myself, I just find that agravating when it is pulled on me.

Re: Search Error Message

Posted: Mon Aug 13, 2018 6:28 am
by FourthWorld
bogs wrote:
Mon Aug 13, 2018 3:45 am
...it would certainly be easier to just put an empty openCard handler on the search stack card and eliminate the field "page" from that stack setup altogether.
Or move the code to the shared group. Either option will work well without needing to add extra stuff.

Re: Search Error Message

Posted: Mon Aug 13, 2018 7:45 am
by bogs
Yep, like most beginner tutorials, it left room for lots of improvements and ways to do things as your skills grow.

The article looks like it was geared towards getting the most bang for the buck from the simplest amount of code, but I could certainly see sticking the page numbering thing any number of other less likely to foul up places, such as the group you mention.

Re: Search Error Message

Posted: Mon Aug 13, 2018 5:49 pm
by jacque
Palettes didn't used to gain focus unless you clicked on them, so the original lesson probably worked when it was written. I'm not sure if the new behavior is intentional or a bug. (I didn't actually try to test it.)

Re: Search Error Message

Posted: Mon Aug 13, 2018 6:16 pm
by FourthWorld
If a field is open for editing, such as the Search field in this palette, the palette would have focus.

To shift focus to another stack for subsequent commands set the defaultStack global property to that stack.

Re: Search Error Message

Posted: Mon Aug 13, 2018 7:24 pm
by bogs
jacque wrote:
Mon Aug 13, 2018 5:49 pm
Palettes didn't used to gain focus unless you clicked on them, so the original lesson probably worked when it was written.
If I was looking at the right lesson that kespears was following, then we are talking about 2014. The Lc in the picture I am guessing is 6.x series, and they talk about Lc being open source, so I am putting it around 6.5.

Re: Search Error Message

Posted: Tue Aug 14, 2018 10:48 pm
by kespears
Bogs, your are correct regarding the 2014 article that I was following.

Thanks to you and FourthWorld and other for your response and direction. Great information. I will try to finish it this evening after visiting my sons school. Schools in on LC and in my neighborhood.

Thanks
Keith

Re: Search Error Message

Posted: Wed Aug 15, 2018 1:35 am
by bogs
Glad we could help Keith :D