Trying to call a button

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Trying to call a button

Post by Danny » Mon Dec 13, 2010 3:34 am

Hello, all
So I'm feeling quite stupid :oops: , I have been trying for the past week to get a specific part of my game to work.

This is the problem: I have a game where these balls drop and the player catch them with a bucket. I'm trying to make it a skill game where a bunch of the balls are falling so it makes it hard for the users to catch. I've made the script (with some big help from the forums) for the balls to drop, count for a point if you caught it, and disappear when it reaches the ground. I've also made the script for the main structure of the game and made the interface. Also I labeled each ball "ball1", "ball2" etc.

But I want the code to pick three random balls and use the code to drop them. So when I press Start the game starts the three balls drop, then another set, and another until the player misses one. I don't know if there is a special handler on the main script to call the balls. If you could help it would be much appreciated. Showing sample code, explaining what I need to do, pointing me towards a lesson (I do like to learn), OR anything else you think could solve my problem would be absolutely amazing.

Thanks,

Danny

P.S Please don't take the reference of balls far
Last edited by Danny on Mon Dec 13, 2010 5:00 pm, edited 1 time in total.

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Trying to call a button

Post by WaltBrown » Mon Dec 13, 2010 12:10 pm

Danny,
You may want to stick with the forum (I saw some of your earlier posts), as they are already familiar with your application questions, here you would have to explain again from the beginning.
[[Oops, ignore that, this is the forum I saw it in, dur]] :oops:

I would just have all the balls in a list or array, and pick them at random from the list. Something like:

Code: Select all

-- List of ball IDs not yet dropped
    global gBallsNotDropped
-- Counter for total balls this round
    global gMaxBalls

-- In my main loop
    local tTime, tNumBalls
    wait tTime milliseconds  -- where tTime is your delay between drops
    doBallDrop(tNumBalls)     -- where tNumBalls is the number you want to drop at once

-- Subroutine to drop a random subset of balls
on doBallDrop pBallCount
   local tWhichBall, tNextBall
   repeat with tNextBall = 1 to pBallCount
      put random(the number of items in gBallsNotDropped) into tWhichBall
      send "dropNow" to <object> <item tWhichBall of gBallsNotDropped> in 0 milliseconds
      delete item tWhichBall of gBallsNotDropped
   end repeat
end doBallDrop

-- In the ball
global gBallsNotDropped, gMaxBalls

on dropNow
   if gMaxBalls then
      copy me to this card  -- Replace the ball about to move with a new one for later
      put comma and it after gBallsNotDropped   -- and add it's ID to the list
   end if
   subtract 1 from gMaxBalls
   -- whatever move function you have for the ball
end dropNow
I'm sure there are lots of ways to do this...
Walt Brown
Omnis traductor traditor

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Trying to call a button

Post by Danny » Mon Dec 13, 2010 5:35 pm

Thanks Walt,
The script looks great but when I tried to run it an error came up on this line of code:

Code: Select all

send "dropNow" to <object> <item tWhichBall of gBallsNotDropped> in 0 milliseconds
and the error said:
"stack "Drop": compilation error at line 51 (Expression: double binary operator) near "<", char 22"

Should I delete those greater than and less than brackets? I did try to fill <object> in with my "bucket" button

Oh and I just explained it again cause some of the other forum users said they didn't exactly know what I was trying to do.

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

Re: Trying to call a button

Post by Klaus » Mon Dec 13, 2010 6:36 pm

Danny wrote:Should I delete those greater than and less than brackets?
Yes.

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Trying to call a button

Post by Danny » Mon Dec 13, 2010 6:45 pm

I got rid of the brackets on the object and got:
"stack "Drop": compilation error at line 51 (repeat: garbage where a command should be) near "<", char 25"

then I got rid of the brackets around item

Code: Select all

tWhichBall of gBallsNotDropped
and got:
"stack "Drop": compilation error at line 51 (Commands: missing ',') near "of", char 37"

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Trying to call a button

Post by WaltBrown » Mon Dec 13, 2010 8:46 pm

Danny, sorry, since I didn't have your code, that had some short cut psuedocode in it, to just describe what I was suggesting. I should have been clearer. The brackets were to indicate generic info - in the send line, I didn't know what kind of object your balls were, so that could be "graphic", or "button", etc.

Check out what you put into gBallsNotDropped initially, it should be a comma separated list of IDs of the ball objects, that you need to build when you initialize the card for play. The missing comma suggests it does not have a list in it. Mine only replaces the ones dropped.
Walt Brown
Omnis traductor traditor

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Trying to call a button

Post by Danny » Tue Dec 14, 2010 12:48 am

WaltBrown wrote: Check out what you put into gBallsNotDropped initially, it should be a comma separated list of IDs of the ball objects, that you need to build when you initialize the card for play.
That got rid of the errors!

When I hit run I got one more error.

Code: Select all

put random(the number of items in gBallsNotDropped) into tWhichBall
execution error at line 16 (random: error in source expression), char 7

I tried a space in between "random" and "the" but it cam up the the same error. Should I fill this with my variables?

This is the code for the balls

Code: Select all

on dropNow
      if gMaxBalls then
      copy me to this card  -- Replace the ball about to move with a new one for later
      put comma and it after gBallsNotDropped   -- and add it's ID to the list
   end if
   subtract 1 from gMaxBalls
   -- whatever move function you have for the ball
 set the icon of button ("ball1") to 6005
   /* hide the cursor whilst the ball drops*/
   put the loc of me into myLocation
   /* drop the ball */
   --move me to (item 1 of myLocation,472) in 40 ticks
   move me to the points of graphic "appleLine1" in 3 seconds
   
   /*hang about for a second ... in the bottom of the bucket*/
   wait 1 millisecond
   /* restore the ball to the start location*/
   set the icon of button ("ball1") to 0
end dropNow
The part where it says

Code: Select all

subtract 1 from gMaxBalls

I got an error which read:
"button "Ball1": execution error at line 6 (subtract: destination has a bad format (numeric?)), char 1"

I did not fill in the global gMaxBalls because it didn't show any results.
Mine only replaces the ones dropped.
Does this code bring the balls back to the game and drop them at random?

Oh and should I fill in any more of those fill ins.

Thanks, and sorry for the long reply

Danny

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Trying to call a button

Post by WaltBrown » Tue Dec 14, 2010 11:01 am

Hi Danny,
Try this. It is by no means the best, and I am sure there are other ways to do it. I made this for LC on Win, not iOS, but it might be some help.
Walt
Attachments
BallDrop.zip
(145.25 KiB) Downloaded 350 times
Walt Brown
Omnis traductor traditor

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Trying to call a button

Post by bn » Tue Dec 14, 2010 11:15 am

Hi Danny,

I noticed in your script, without really knowing what is going on:

did you initialize the global variables outside of the script? I don't see the initialization, that is a frequent source of errors.

here

Code: Select all

if gMaxBalls then
you use gMaxBalls as a boolean, i.e. it is either true or false. later on

Code: Select all

 subtract 1 from gMaxBalls
you do calculations on the variable, suggesting it should contain numbers.

Kind regards

Bernd

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Trying to call a button

Post by WaltBrown » Tue Dec 14, 2010 11:36 am

Hi Berndt,
That was mine, I was using that integer value to count down to zero.
Walt

- Which for some reason I just assumed worked, but discovered not in LC. My assumption was from too many other programming languages. :|
Walt Brown
Omnis traductor traditor

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Trying to call a button

Post by Danny » Fri Dec 17, 2010 4:41 am

Hey Walt and bn,
Sorry for the long wait between posts. :(
The app is starting to come together but I have another question or two. I am trying to use

Code: Select all

wait (how ever many seconds you choose) seconds 
because when I run it in the simulator the ball lands and then I can't move the bucket until 1 second or whatever I put in the wait field has run. Is there a way I can use the wait feature without it freezing the screen? Walt I know you don't have the iOS plug in I just wasn't sure if you knew how to fix this.

Do you know if there is a timer function that can almost make rounds to make the game progressively tougher like after 60 seconds the balls start again with 30 balls falling after the round of 20? I'd like to make it time based if I can.

Last, is there a command to get the game to end if the player drops one?

Thanks!

Danny

P.S Anyone else can chime in if they can help

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Trying to call a button

Post by WaltBrown » Fri Dec 17, 2010 5:58 am

Danny,
Instead of using "wait" check out "send" in the dictionary, as in "send someMessage to someObject in xxx seconds", and in that object (card, stack, button, etc) have a handler for "on someMessage". Also check the similar command "dispatch".
Walt
Walt Brown
Omnis traductor traditor

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Trying to call a button

Post by Danny » Sat Dec 18, 2010 2:04 am

Sorry Walt that didn't seem to work. I did understand what you said, but it was still freezing the picture in the simulator. I've tried the "without waiting" but that didn't do any good. Do you think that a timer would work instead of the "wait" code. So after the timer runs for 3 seconds the the ball drops.

Edit: Never mind I got it to work. :D

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Trying to call a button

Post by Danny » Tue Dec 21, 2010 3:14 am

Um I have been trying to make

Code: Select all

 set the icon of button "ball3" to 6002 
appear after a certain time but when I put in "in xxx seconds" it says
"button "ball3": compilation error at line 30 (Commands: missing ',') near "seconds", char 46"
Any ideas?

Please look at next page for a reply
Last edited by Danny on Fri Dec 24, 2010 2:00 am, edited 1 time in total.

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

Re: Trying to call a button

Post by Klaus » Tue Dec 21, 2010 12:27 pm

Hi Danny,

"that not works", as you have experienced :D

You need to "wrap" a handler around your commands and then cans you SEND this new handler in X secs.
You could use a little more generic handler, maybe in the card script:

Code: Select all

command SetIconToBall tButtonName,tIcon
  set the icon of btn tButtonName ot tIcon
end SetIconToBall
and call it:

Code: Select all

...
send (SetIconToBall && QUOTE &"ball3" & "," & 6002) to this card in 3 secs
...
whenever it is neccessary.

Best

Klaus

Post Reply