Page 1 of 2
SCRAMBLED IMAGES
Posted: Fri Nov 09, 2012 2:25 pm
by danymar
Help me, please...
I'm creating a game (a special game as "guess who") and I need to have some images (12) that appear randomly at the open page, changing their position (4 x 3 board).
Furthermore I need to have one copy of other images that appear randomly in the right-bottom of the page.
I don't know how to realize that because I'm confusing with the variables.
Thank you for your help

Danymar
Re: SCRAMBLED IMAGES
Posted: Fri Nov 09, 2012 10:53 pm
by Mark
Hi Danymar,
Could you be more specific about your confusion with variables? What have you tried so far and at which point do you get stuck?
If your app is going to have only 12 images, then you might want to import all of them on a card, which you're not going to use for anything else (e.g. the last card in your stack or even a card of a substack, which you won't use for anything else). After importing your images, change their ID numbers to something like 101001, 101002 etc. Now create a new button in the bottom-right on the first card of your mainstack and use the property inspector to set the icon property of the button to 101001. You'll see that a picture appears in the button. You can do this by script:
Code: Select all
on mouseUp
set the icon of btn 1 to 101000 + random(12)
end mouseUp
Instead of a mouseUp handler, you can use a preOpenCard handler to set the random picture when the card opens for instance.
Kind regards,
Mark
Re: SCRAMBLED IMAGES
Posted: Fri Nov 09, 2012 11:11 pm
by danymar
Dear Mark,
I've tried your suggestions but nothing appears on my screen.
I've created a substack called IMAGES and I've changed ID as you suggested. 101001 was too big (told me the software), so I've tried with 10001 and so on until 10012.
Then I've put a mouseUp handler on with your script.
I've tried also with preOpenCard but nothing happens.
Maybe I'm wrong with instruction on other level of hierarchy (i.e. setting the board)?
What's your suggestion for scrambled images in the grid 4x3?
Thank you so much, I'm in deep difficult 'cause I'm totally new.
Re: SCRAMBLED IMAGES
Posted: Sat Nov 10, 2012 12:15 am
by Mark
Hi Danymar,
I think you're trying to go too fast. First, you need to be able to create an image and and a button and set the icon of the button to the id of the image. Once you know how to do this, you can make your grid with pictures.
Which ID did you change exactly? Where did you change this? If I create an image and change the image to a really large number, LiveCode says something like "not an integer". Is this the error you see? ID numbers can be anything between -2147483586 and 2147483586, so the height of the ID number shouldn't be an issue.
Anyway, 10001 is fine, if you change the script too:
Code: Select all
on mouseUp
set the icon of btn 1 to 10000 + random(12)
end mouseUp
Other things to check: make sure that the mainstack of substack IMAGES is not stack IMAGES but really your mainstack. Type this in the mesage box
Code: Select all
put the mainstack of stack "Images"
and check the message box doesn't return "Images".
Did you use the menu item "Import as Control/Image File..." to import the images into your substack?
Where did you put the mouseUp handler? Did you put the preOpenCard handler in the card script and not anywhere else? Are you sure that the preOpenCard handler actuall ran? You can check this with a line like
which should show a window with the text "I'm running".
I don't know what you mean with "setting the board". Can you explain this?
Re: SCRAMBLED IMAGES
Posted: Sat Nov 10, 2012 4:25 pm
by danymar
I think you're trying to go too fast.
It's true but I need to develop game for my pupils at school and time goes by quickly
Which ID did you change exactly? Where did you change this? If I create an image and change the image to a really large number, LiveCode says something like "not an integer". Is this the error you see? ID numbers can be anything between -2147483586 and 2147483586, so the height of the ID number shouldn't be an issue.
The message told me "this number is property of RunRev" but today it's ok. So I've fixed 1000001 as you suggested
Other things to check: make sure that the mainstack of substack IMAGES is not stack IMAGES but really your mainstack. Type this in the mesage box
It's ok, it returned "Card Game" (the name of my mainstack)
Did you use the menu item "Import as Control/Image File..." to import the images into your substack?
YES
Where did you put the mouseUp handler? Did you put the preOpenCard handler in the card script and not anywhere else? Are you sure that the preOpenCard handler actuall ran? You can check this with a line like
I put the mouseUp in the button script, but I didn't understand if the handler of preOpenCard is to put TOGETHER with the mouseUP handler or in alternative
The script of the button runs
I don't know what you mean with "setting the board". Can you explain this?[/quote]
I've seen a script exemple in Internet with a command to set a puzzle with the command "createboard 3x3"
Now that the button runs, can I advance to next level? 
Re: SCRAMBLED IMAGES
Posted: Sun Nov 11, 2012 1:02 am
by Mark
Hi,
It seems to work, so lets try something new. There are many ways to create a grid. It seems to be sufficient for you to just make 12 transparent buttons. You can position them manually on the card. Give them names, e.g. Gid 1, Grid 2... Grid 12. Now you need a script that gets a list of pictures and sets the icons of the buttons to the id numbers of these pictures.
You can get the list of pictures with a repeat loop:
Code: Select all
repeat with x = 1 to number of images of cd 1 of stack "Images"
put the long id of img x of cd 1 of stack "Images" & cr after myList
end repeat
put myList -- so you can see what it looks like in the msg box
sort lines of myList by random(12) // hussle the lines
repeat with x = 1 to number of lines of myList
set the icon of btn x of this cd to the id of \
line x of myList
end repeat
Put this in a mouseUp handler in a button script or in a preOpenCard handler of a card script. Btw the best place for a preOpenCard handler is often the card script.
I think that you now have all the basics of your app.
Kind regards,
Mark
THANK YOU MARK
Posted: Sun Nov 11, 2012 9:05 pm
by danymar
I would to thank you for your kind collaboration.

Re: SCRAMBLED IMAGES
Posted: Sun Nov 11, 2012 11:27 pm
by Mark
Hi,
You're welcome. Btw I just noticed that I wrote "img" instead of "btn" somewhere. I have corrected the script.
Kind regards,
Mark
Re: SCRAMBLED IMAGES
Posted: Mon Nov 12, 2012 12:10 am
by danymar
Thank you Mark, I've already seen and corrected but the script doesn't run.
The script returns all the long id of images in a list that I see in the message box but the buttons "grid_x" don't change aspect and the list seems to be always the same, without randomize the position

.
Have you received my private message (by means of you website) regarding your book?
Re: SCRAMBLED IMAGES
Posted: Mon Nov 12, 2012 1:01 am
by Mark
Hi,
The list is put into the message box before it is sorted. Switch those two lines and you will see the randomized list.
What exactly do you mean with "change aspect"? Do you want the button to change their aspect ratio automatically?
Can you check in the button properties inspector to which values the icon properties are set? Are they the same as the id numbers of the images? Are you sure that nothing happens? No error message or strange pictures or anything else unexpected?
It always takes a little while before you get a reply to e-mails, because there is a long queue and all e-mails are anwered chronologically to keep it fair.
Kind regards,
Mark
Re: SCRAMBLED IMAGES
Posted: Mon Nov 12, 2012 5:10 pm
by danymar
Mark wrote:
The list is put into the message box before it is sorted. Switch those two lines and you will see the randomized list.
I was able to randomize lines only putting them into a field. Now I can see how all the lines (with their long ID) can scramble - Good
What exactly do you mean with "change aspect"? Do you want the button to change their aspect ratio automatically?
I only want that all the random images go into one of the "grid" buttons and that they could be visualized in a different way each time.
Can you check in the button properties inspector to which values the icon properties are set? Are they the same as the id numbers of the images? Are you sure that nothing happens? No error message or strange pictures or anything else unexpected?
The images are right. After I see all the scrambled lines, the script finds difficulty with the command "set the icon of btn x of this cd to the id of line x of myList", as it wasn't able to transform the "long id", written on the line, into an image to set in the button. I think that if this problem could be solved, the app could run.
Thanks a lot
Dany
Re: SCRAMBLED IMAGES
Posted: Mon Nov 12, 2012 6:05 pm
by jacque
The line should be:
set the icon of btn x of this cd to (line x of myList)
Or you can do it in two lines:
get line x of myList
set the icon of btn x of this cd to it
EDIT: I just noticed the list contains long IDs. Those won't work. Change the list to use the short ID instead.
Re: SCRAMBLED IMAGES
Posted: Mon Nov 12, 2012 6:58 pm
by Mark
Jacque,
I wrote: the id of line x of myList
That works. Please, try not to add to the confusion.
Danymar, my script should work, but I will look at it again and at your replies later today.
Mark
Re: SCRAMBLED IMAGES
Posted: Mon Nov 12, 2012 7:54 pm
by Mark
Danymar,
Adding the parentheses should be enough:
Code: Select all
on mouseUp
repeat with x = 1 to number of images of cd 1 of stack "Images"
put the long id of img x of cd 1 of stack "Images" & cr after myList
end repeat
put myList -- so you can see what it looks like in the msg box
sort lines of myList by random(12) // hussle the lines
repeat with x = 1 to number of lines of myList
set the icon of btn x of this cd to the id of \
(line x of myList)
end repeat
end mouseUp
I created a button with this handler to do a quick test, but it should also work in e.g. a preOpenCard handler.
Reading your previous post, I think that "the script finds difficulty with the command..." actually means "an error occurred at the line...". If an error happens again, it would be very useful to post the complete text of this error. Just copy it and paste it here in the forum. Whenever you have a question that involves an error, please post the error together with your question.
Kind regards,
Mark
Re: SCRAMBLED IMAGES
Posted: Mon Nov 12, 2012 10:16 pm
by danymar
Hi Mark, finally it works!!
I've put in the card script this handler
on preOpenCard
repeat with x = 1 to number of images of cd "clowni" of stack "Cards Game"
put the id of img x of cd "clowni" of stack "Cards Game" & cr after myList
end repeat
Where "clowni" is a card in the stack "Card Games" that contains all clown images to be randomized -
put myList into field "ecco" -- so you can see what it looks like in the msg box
sort lines of field "ecco" by random(12) // hussle the lines
"ecco" is the field where myList variable is visualized and where the lines are going to be scrambled - Actually is visible (bottom-right of the page) but I'll put it "not visible" later
repeat with y= 1 to number of lines of field "ecco"
set the icon of btn y of group "grid" of this cd to (line y of field "ecco")
end repeat
end preOpenCard
group "grid" is the group of buttons called "grid1, grid2 etc." where the icon are going to be setted - Unfortunately I had to change in your script the variable x with y because it seemed to have problems to understand which was the correct variable to run
The yellow clown is a random image as you suggested me before, during our last mail exchange.
Thank you again for your kindly cooperation - Now I will study the prosecution of the game, where I have to select the right clown on a base of some questions.
Bye
