Random Pop-Ups

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

unclewayne
Posts: 37
Joined: Tue Apr 05, 2011 9:58 pm

Random Pop-Ups

Post by unclewayne » Mon Jul 11, 2011 6:44 pm

I have about 20-30 pop up graphics that i would like to pop up randomly through out the game. The game is a really simple shooting game and every time you shoot the score goes up by 1. I would be ok with having these pop ups show up every 5 or so. They can should also stay up until the next one pops up. Any help would be great.

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

Re: Random Pop-Ups

Post by Klaus » Mon Jul 11, 2011 7:36 pm

Hi Wayne,

OK, at what part exactly are you needing help?
Randomize the locs of the graphics?
Showing/hiding graphics?
Memorizing the current "pop-up" graphic in a local of global variable (or custom property) and hide that one when the next one pops up?
"send" a command every X seconds?


Best

Klaus

unclewayne
Posts: 37
Joined: Tue Apr 05, 2011 9:58 pm

Re: Random Pop-Ups

Post by unclewayne » Mon Jul 11, 2011 8:14 pm

How to show a random pop up every 5 points.
I have them in the locations they should be in and set the visible off.

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

Re: Random Pop-Ups

Post by Klaus » Tue Jul 12, 2011 2:42 pm

Hi Wayne,

OK, here a "fake" script that should get you started:

Code: Select all

local the_last_popup
## Will store the name or ID of the last popup graphic
command los_popups
  if the_last_popup <> empty then
     hide img the_last_popup
  end if

  ## Show a random image.
  ## You might need to maintain a list of these images somewhere,
  ##  so you cann access it and "pull" out a random image
  show img XYZ
  put XYZ into the_last_popup

  ## Now you need a conditon to NOT show an image anymore:
  if your_condtion_here = true then
   exit los_popups
  end if

  ## The show goes on in 5 secs:
  send "los_popups" to me in 5 secs
end los_popups
Best

Klaus

unclewayne
Posts: 37
Joined: Tue Apr 05, 2011 9:58 pm

Re: Random Pop-Ups

Post by unclewayne » Tue Jul 12, 2011 3:26 pm

So i have:
1.jpg
2.jpg
3.jpg
4.jpg
Up to 30.jpg

I want nothing to show up for the first 5 points than at 5 it would randomly pick one of my jpg's, then at every 5 points it would randomly pick another of the jpg's to appear and stay up for the next 5 points.

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

Re: Random Pop-Ups

Post by Klaus » Tue Jul 12, 2011 3:30 pm

...then you should use the script (or parts of it) in your "point calculation" routine:

...
if totalpoints = 5 then...
...

You get the picture!


Best

Klaus

unclewayne
Posts: 37
Joined: Tue Apr 05, 2011 9:58 pm

Re: Random Pop-Ups

Post by unclewayne » Tue Jul 12, 2011 8:36 pm

I am still really lost. I tried all the tricks i had and nothing is working.

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

Re: Random Pop-Ups

Post by Klaus » Wed Jul 13, 2011 1:03 pm

Wayne,

what do you have so far? What did you try so far?


Best

Klaus

unclewayne
Posts: 37
Joined: Tue Apr 05, 2011 9:58 pm

Re: Random Pop-Ups

Post by unclewayne » Wed Jul 13, 2011 3:18 pm

this is where I left off yesterday:

If field "score" =(x)5 then
place random 150, 180 (1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg)
end if

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

Re: Random Pop-Ups

Post by Klaus » Wed Jul 13, 2011 4:27 pm

Hi Wayne,

well, this is indeed meager! 8)
Please post more infos, scripts etc. if you don't want to last this until christmas :wink:

I am sure you already looked up the terms "place" and "random()" to understand why that snippets does not work, right?
"place" will place GROUPS or Backgrounds onto a card
"random" is a function and needs a parameter that can be "randomized"

As far as I understood so far you already have these images on the correct card but all images are hidden so far, right?
So you need to show/hide these images when a certain conditon happens.

Where did you try to add this snippet?
What does "150,180" mean in your snippet?

As I wrote in an earlier mail you should "hook" into the "points calculating" handler that you have (if any).

Please explain what you want to do to yourself (and us) in PLAIN english and I bet you will be able to translate it almost 1:1 to LiveCode.
Again I think your are thinking far too complicated!

Like this:
When the points are at least 5 or a multiple of 5 (right?) then I want ...


Best

Klaus

unclewayne
Posts: 37
Joined: Tue Apr 05, 2011 9:58 pm

Re: Random Pop-Ups

Post by unclewayne » Wed Jul 13, 2011 4:51 pm

Sorry, I am making it more complicated than it need to be. I added this to the card script.
Here it is broken down:

I have 30 images (1-30.jpg) set at the same spot (150,180). they are all set to not visible on the card. When the score hits a multiple of 5 i would like it to randomly display 1 of the 30 images that are hidden and stay visible until the next multiple of 5.

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

Re: Random Pop-Ups

Post by Klaus » Wed Jul 13, 2011 5:04 pm

Hi Wayne,

aha, we are moving along :D

Do you have a handler that counts your points?
We could and SHOULD hook intot that scripts!

I would use a BUTTON and just set its ICON to the ID of your image!
This way you do not need to hide a previously shown image!
Set the loc of this button to 150,180 and that's it (almost) :D

This needs some preparation: a list of the IDs of your images, preferrably CR delimited, ONE id per line!
Then you can simply:

Code: Select all

...
 if (total_points >= 5) AND (total_points mod 5 = 0) then
 ## Greater than 5 AND a multiple of 5!

   set the ICON of btn "your button that shows the images here" to ANY line of list_with_image_IDs
   ## or: .. ANY line of fld "list_with_image_IDs" or wherever you decide to store this info
end if
...
Get the picture?
I would add this to your "points calculation and display" handler after actually setting the points.


Best

Klaus

unclewayne
Posts: 37
Joined: Tue Apr 05, 2011 9:58 pm

Re: Random Pop-Ups

Post by unclewayne » Wed Jul 13, 2011 5:16 pm

I am 98% with you. I have a field called "score" holding the points.

This is what is tripping me up:
This needs some preparation: a list of the IDs of your images, preferrably CR delimited, ONE id per line!
how do i make the list?

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

Re: Random Pop-Ups

Post by Klaus » Wed Jul 13, 2011 5:24 pm

Hi Wayne,

you could do this manually, select the images and look up their ID in the Inspector palette or use a little script to do so:

Code: Select all

...
put empty into tIDList
repeat with i = 1 to 30
  put i & ".jpg" into tImageName

  ## This requires that all images are on the card where you execute this script or you get an error "Object not found..."!
  ## Otherwise you need to add a decriptor:
  ###  ... of img tImageName OF CD X ## of stack Y
  put the ID of img tImageName & CR after tIDList
end repeat

## Get rid of trailing CD
delete char -1 of tIDList
put tIDList into fld "ID list"
## or whereever...
...
Best

Klaus

unclewayne
Posts: 37
Joined: Tue Apr 05, 2011 9:58 pm

Re: Random Pop-Ups

Post by unclewayne » Wed Jul 13, 2011 5:54 pm

Sorry. I have to learn to be more clear.

Where do i make the list?

SO now i have a button at 150, 180 where do i list the IDs of my images? "list_with_image_IDs"

Post Reply