Page 1 of 1

Changing blocks to different colors

PostPosted: Fri Mar 21, 2008 6:38 pm
by laserman
Here's a tall order, but if anyone can help, it would be much appreciated. I have uploaded an image in case anyone can accomplish this. The image is very rough but serves the purpose I believe.

I have 3 rows of 4 squares each.
I want to be able to click on a square and have an option box pop up to ask the user to enter a number from 1 - 9. After the user enters the number (and presses Enter or clicks on OK), according to the number they entered, the block selected will turn a predetermined color associated with that number and stay that way when saved and loaded.

Is this clear enough? If not, let me know and I will try and explain it differently. Thanks for any considerations.

PostPosted: Fri Mar 21, 2008 7:04 pm
by Lyberodoggy
Hello and welcome to the Forums!

Okay, here's what you 've got to do:
create a hotspot over each block.
Write this piece of code in advanced:
Code: Select all
color=InputBox("input a number between 1 and 9")
Select Case color
 case 1
 Action.LoadAPicture Hotspot(Action.GetHotspotNumber), "green.jpg"
 case 2
 Action.LoadAPicture Hotspot(Action.GetHotspotNumber), "red.jpg"
 case 3
 Action.LoadAPicture Hotspot(Action.GetHotspotNumber), "purple.jpg"
 case 4
 Action.LoadAPicture Hotspot(Action.GetHotspotNumber), "yellow.jpg"
 case 5
 Action.LoadAPicture Hotspot(Action.GetHotspotNumber), "black.jpg"
 case 6
 Action.LoadAPicture Hotspot(Action.GetHotspotNumber), "white.jpg"
 case 7
 Action.LoadAPicture Hotspot(Action.GetHotspotNumber), "gray.jpg"
 case 8
 Action.LoadAPicture Hotspot(Action.GetHotspotNumber), "maroon.jpg"
 case 9
 Action.LoadAPicture Hotspot(Action.GetHotspotNumber), "olive.jpg"
End Select

Where you must replace green.jpg etc with the name of 9 pictures representing the 9 colors you need to display.

Hope this helped... If you need any explanations, feel free to ask...

EDIT: Fixed that bug... it should work now...

PostPosted: Sat Mar 22, 2008 5:09 am
by laserman
Thanks for the quick reply.
I did that, but I got this message:

Error executing script.
The scripting engine returned the following error message
Expected "End"

I'm not sure what it's looking for. Also, where do I paste the code? I see 2 places. Is it the hotspot properties box, or the one under the menu? I did it in the hotspot properties box.
Thanks again.

PostPosted: Sat Mar 22, 2008 9:05 am
by Lyberodoggy
My mistake... I got the whole code wrong...

You can find the debugged version in my previous post, I edited it...

Sorry I should have tested it...
Ah, I must mention the "else case" wouldnt work so I deleted it. If you want to check whether the input number is between 1 and 9 to continue, add these lines
here goes the first line of the original code, then write this one:
Code: Select all
If 1<=color<=9 then

here goes the rest of the rest of the original code, then write:
end if

I 'm not sure if this is going to work, but the rest works...

PostPosted: Sat Mar 22, 2008 2:43 pm
by laserman
That was beautiful. thanks.
The error checker didn't work, but that's okay. The code did.

This brings up another question as long as you don't mind....

I had assumed that the pictures I made would (how can I put this) be "layered" over the original according to the hotspot coordinates, so that no matter what block I chose, the colored blocks would be in the same spot I clicked on after entering the associated number. This didn't happen. What did happen was that the colored block would replace the 12 block image.

To avoid being a pain in the butt here, I experimented and found that if I make my colored blocks into AVI files then I could select the coordinates. However (and as you most likely well know) I can only choose 1 video for each area of the original block image. This of course defeats the whole purpose of being able to put whatever color I choose, wherever I want on the original image and (of course) however many I want also.

I hope I'm not being confusing here.

So my question now is: How would I accomplish "layering" in this sense? Thanks again for your consideration.

PostPosted: Sat Mar 22, 2008 3:11 pm
by Lyberodoggy
If I got your point, you created only one hotspot... Well that is definitely wrong. You must create one hotspot for each block. I 'm attaching a sample project.

PostPosted: Sat Mar 22, 2008 5:12 pm
by laserman
It worked great! That is what I am talking about.
So apparently I create 1 hotspot for each block, with the code, and that is what allows me to chose whatever colors I want. I am assuming also that if I save it, it will be saved with the colors I left off on when I load it again later on?

Thanks so much for this. Amazing how simple the solution was,
I will of course have more questions as time goes on. I will post them here as this progresses. Thanks again you've been an amazingly big help.
2 big thumbs up to you.

PostPosted: Sat Mar 22, 2008 5:32 pm
by Candle
Going to move this to Tutorials so others can find it and use it.

PostPosted: Sat Mar 22, 2008 7:10 pm
by Lyberodoggy
To laserman: Thanks for your good words, it's always nice to be of help and I will definitely try to help you if you have any other difficulties.

To Candle: Yes, nice idea Candle!