handler objects on other cards

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
churchken
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 66
Joined: Sun Apr 15, 2007 2:54 pm

handler objects on other cards

Post by churchken » Thu Oct 18, 2007 12:49 am

Hi,

Is it possible to force a card script handler running on card"A" to limit its field object references to only that card, without adding ( of card"A" ) after every field reference in the entire handler?

This came up when I took a card with many fields and a script that calculates values for those fields, and "added" it to another stack. If I "go to " a different card in the stack while the first card handler is still working, errors pop up because the handler wants to put a value into a field that is not on the new card, but is on the original card.

Hope that makes sense, and thanks for any help.

Ken

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Oct 18, 2007 2:30 am

Hi Ken,

I wonder why your script is still running while you go to a different card already. Figuring out why this happens and whether it is really necessary is probably an important part of the actual solution.

You could write a script that stores all values in variables until all repeat loops have finished and the values can be put into fields. Such a script might look like this.

Code: Select all

on longCalculation
  -- zillions of lines in myData
  repeat with x = 1 to (number of lines of myData)
    -- do something with line x of myData
    -- store values in an array if necessary
    put myResult1 into myValuesArray["put short name of field 1 here"]
    put myResult2 into myValuesArray["put short name of field 2 here"]
    -- and so on
    put myResultX into myValuesArray["put short name of field X here"]
  end repeat
  -- any more results to be stored?
  put myResultY into myValuesArray["put short name of field Y here"]
  put myResultZ into myValuesArray["put short name of field Z here"]
  -- go to card with the field without bothering user
  push cd
  lock screen
  go cd 1 -- card containing the fields that need to be filled out
  -- now we're finally done and can put values into fields
  repeat for each key myKey in myValuesArray
    put myValuesArray[myKey] into fld myKey
  end repeat
  pop cd
end longCalculation
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

churchken
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 66
Joined: Sun Apr 15, 2007 2:54 pm

different, on-going tasks

Post by churchken » Thu Oct 18, 2007 1:30 pm

Mark,

Thanks for your coding suggestion.

There is a "why" to go from one card to another while handlers are still working on each card. There is "new data" continuously being fed into each card via a socket connection to another program. Each card has its own "tasks", but I would like to be able to view the status of each card without halting the tasks being carried out on the other card.

Perhaps REV does not "like" this approach, and I need to separate the tasks into stand alone applications. This is not ideal for me, since the results of tasks on both cards are ultimately used in combination with each other in a third decision tree.

Thanks for any additional suggestions you might have.

Regards,
Ken

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Oct 18, 2007 1:37 pm

Hi Ken,

One more question. Why is it inconvenient or problematic to add "of card xxxx" to your code?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

churchken
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 66
Joined: Sun Apr 15, 2007 2:54 pm

Post by churchken » Thu Oct 18, 2007 1:49 pm

Mark,

If there is no simpler way, then adding "of card A" is probably what I will do.

It is a matter of convience not to do so, since future duplication of the handler script that is being used on card A (for use on cards "B" and "C", etc. ) is probable. Yes, :D , I do know how to use an editor.

Anyway, thanks for your assistance.

Regards,
Ken

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Oct 18, 2007 1:59 pm

Hi Ken,

Why would you duplicate a handler? Why don't you raise the handler to the level of the stack script and adjust it to make it understand parameters that contain the id of the card?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

churchken
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 66
Joined: Sun Apr 15, 2007 2:54 pm

Post by churchken » Thu Oct 18, 2007 2:11 pm

Mark,

That makes perfect sense, and in the long run is the best idea.

Thanks so much,
Ken

Post Reply