Access field in a card from script only stack

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
foosmaster
Posts: 30
Joined: Mon Apr 13, 2020 8:46 am

Access field in a card from script only stack

Post by foosmaster » Mon Apr 13, 2020 3:45 pm

I have a library stack which handles web services calls/events
I get an event from the server in the script only stack, and I want to update a field in the currently active card.
basically this happens as a result of async load URL <> with message "GameEvent"
then in GameEvent I want to update the player name, I know the card name, I know the label's name, i tried:

Code: Select all

set text of field "player1name" to pname
no luck, I tried this

Code: Select all

set text of field "player1name" of card "declare" to pname
still no luck, I keep on getting
stack "GuiController": execution error at line 58 (Chunk: can't find card), char 17
<< I wanted to put an image - but it seems I can't :( >>

of course this isn't the stack the card "declare" is included in.

do I need to use the card in a special way from the stack ?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Access field in a card from script only stack

Post by richmond62 » Mon Apr 13, 2020 4:36 pm

ОК: to be honest I've never worked with a script-only stack, BUT I should imagine
that calling a field on another stack from a script-only stack is exactly the same
as calling a field on one stack from another.

Let us imagine for a moment 2 stacks called "mStack" and "sStack" for 'main stack' and 'sub stack' respectively.

Now let us suppose there is a script in stack "mStack" that wants to get some information out of a field on stack "sStack",
one might have a script of this sort:

Code: Select all

put fld "dataIneed" of card "KARD" of stack "sStack" into fld "gottit" of card "homeCard" of stack "mStack"
or, similarly:

Code: Select all

put fld "dataIneed" of card "KARD" of stack "sStack" into GOTTIT
Now . . . for some odd reason I would suppose a script-only stack has no cards and no controls so ALL you might be doing is calling functions.

Code: Select all

do "on crazyFunction" of stack "sStack"
Or, the other way round [from a script-only stack]:

Code: Select all

put DATAiNEED of stack ""sStack" into fld "gottit" of card "homeCard" of stack "mStack"

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Access field in a card from script only stack

Post by FourthWorld » Mon Apr 13, 2020 5:09 pm

Hard to say for sure without seeing the full context, but when a card can't be found and you know it exists in a certain stack, including the stack name in the object reference will resolve that ambiguity.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

foosmaster
Posts: 30
Joined: Mon Apr 13, 2020 8:46 am

Re: Access field in a card from script only stack

Post by foosmaster » Mon Apr 13, 2020 7:45 pm

Code: Select all

of stack "mStack"
did the trick, thanks a lot :)

Post Reply