counting and tables - 2 problems

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
synaptic
Posts: 11
Joined: Thu Jun 04, 2009 10:47 pm

counting and tables - 2 problems

Post by synaptic » Mon Aug 24, 2009 11:39 pm

I have two cards in my stack: One runs some graphics, and the other records various numerical properties of what the graphics have done - or at least, that's what it's supposed to do.

Problem 1) I'm measuring the distance in pixels that 2 gif images have traveled. I am able to do this just fine. When I run the table card from itself, the two measurements are inserted correctly into the table field. However, if I send a mouseup from the "graphics" card to the "table" card, it says, (Chunk: no such object) near "Table Field" This is script for the "table" card:

Code: Select all

on mouseup
   global travel1, travel2  
   
   set itemdelimiter to tab   
   
  put travel1 into first item of field "Table Field"  

   
   put travel2 into second item of field "Table Field"
  
   
  
end mouseup
Problem 2) It would be useful to use a variable instead of "first" and "second" so I can actually run the program more than 1 time, and so the data makes its way to the next available spot in the table. Despite hours of trying, I can't work out how to write a counter, though.

Any help with these matters would be, as usual, greatly appreciated...

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Mon Aug 24, 2009 11:48 pm

I wouldn't bother with global variables and sending a mouseUp from one card to the other.
Just reference the card in the destination, as in:

Code: Select all

put travel1 & tab & travel2 & cr after field "Table Field" of card "table"
As you can see above, you can also just concatenate the line including tabs, and add a carriage return. Putting data "after" a destination name, well you can see, it appends the new stuff "after" what's already there. You will perhaps have to initialise the table field to empty at whatever point is needed, and if you need to do any processing on the list of results you should delete the blank line at the end of the field (that will be created because of the trailing "& cr" being put after the results) but this should be pretty basically what you need, I think.

HTH

synaptic
Posts: 11
Joined: Thu Jun 04, 2009 10:47 pm

Post by synaptic » Mon Aug 24, 2009 11:53 pm

Oh, that was brilliant! Thanks so much.. it's going to be a lot nicer once I get past this whole newbie thing.

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Tue Aug 25, 2009 12:05 am

You seem like you're getting into some good stuff already though. Out of interest, what syntax were you using for sending the message to the table card? And as it was a mouseUp event that was being sent, were you sending it to a button on the table card?
I'd imagine you'd have needed something like

Code: Select all

send "mouseUp" to button "theButton" of card "table"
You can reference objects across stacks and substacks like this too, as in something like

Code: Select all

get field "someDataField" of card "DataHolder" of stack "theSubstackThatOnlyStoresInfo"

synaptic
Posts: 11
Joined: Thu Jun 04, 2009 10:47 pm

Post by synaptic » Tue Aug 25, 2009 12:50 am

No, I was just sending a plain mouseUp to the whole card... perhaps that is what created my issues? I don't know. I do know that if I were to simply click manually on the card, it worked fine.

SparkOut
Posts: 2945
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Tue Aug 25, 2009 8:20 am

Ah, so the mouseUp handler was in the card script. It should have worked if you'd done

Code: Select all

send "mouseUp" to card "table"
in theory.

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Tue Aug 25, 2009 1:10 pm

Hi all,

a much better = efficient was is to "outsource" the actual action in a handler in the stack script or a library and then simply call this handler in a "mouseup" or whenever you need it!

In the stack (or library):

Code: Select all

on fill_in_items
   global travel1, travel2     
   put travel1 & tab & travel2 & cr after field "Table Field" of card "table" OF STACK "Another stack" 
end fill_in_items
Now you can simply call this handler in your button:

Code: Select all

on mouseup
   fill_in_items
end mouseup
And everywhere you need it without fiddling around with "send mouseup to XYZ".
You get the picture.

You will appreciate this technique not later than after you noticed that you wrote (the same) handler in two (or more) different locations :)


Best

Klaus

Post Reply