"Clicking" array help
Author |
Message |
XXX111
|
Posted: Sun Dec 19, 2010 2:27 pm Post subject: "Clicking" array help |
|
|
I'm making a trivia-based multiple choice game where the user always has 4 options to choose from. Since I want to include the same graphics each time, I made separate pictures for each question. Right now, this is how I detect if the user clicks the right "button" (just a specific area of the screen where the picture of the button appears).
Turing: |
if x>= 10 and x<= 30 and y>= 100 and y<= 200 and mousebutton= 1
then delay(200)
put "Correct"
delay(1000)
cls
|
I could do this for every single question, but is there a better way to do this by using arrays? Also, since the multiple choice answers change, the coordinates of the "button" would have to change as well. Any help is greatly appreciated. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sun Dec 19, 2010 2:37 pm Post subject: RE:"Clicking" array help |
|
|
Keep a 2D array of buttons, where the first dimension is the button number and the second dimension contains the coordinates. Alternatively you could create a type button record and have an array of those. Then it's a matter of looping over the array and checking collision against each button. |
|
|
|
|
![](images/spacer.gif) |
TokenHerbz
![](http://compsci.ca/v3/uploads/user_avatars/717170395558e628d9452b.jpg)
|
Posted: Sun Dec 19, 2010 5:39 pm Post subject: RE:"Clicking" array help |
|
|
using an array of type button would be the ideal way to do this,
with that array you could go threw each question, checking the buttons for the answer to display the results/take next action. |
|
|
|
|
![](images/spacer.gif) |
XXX111
|
Posted: Sun Dec 19, 2010 8:43 pm Post subject: Re: "Clicking" array help |
|
|
thanks for your answers, but wouldn't creating a record type require turing to read the actual text? My question is displayed as a picture, so Turing won't be able to tell what the question is. |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sun Dec 19, 2010 8:49 pm Post subject: RE:"Clicking" array help |
|
|
A record is just a handy way of storing lots of related variables. A 'button' record would be something like this:
Turing: |
type button :
record
x1, x2, y1, y2 : int
image : string
end record
var button1 : button
button1.x1 = 5
button1.y1 = 20
button1.x2 = 55
button2.y2 = 40
button2.image = "button.bmp"
|
Yeah, the formatting lines up oddly, but that's okay. This allows you to quickly initialize the buttons via a loop (assuming your buttons are drawn in a mathematically-representable way). It's a bit cleaner than a 2D array and is easier to read. |
|
|
|
|
![](images/spacer.gif) |
XXX111
|
Posted: Mon Dec 20, 2010 8:49 am Post subject: Re: "Clicking" array help |
|
|
Ok I think I get it now! Thanks for all of your help! |
|
|
|
|
![](images/spacer.gif) |
|
|