Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Buckethead on Sat 12/01/2008 17:36:22

Title: Triangle puzzle like in openquest
Post by: Buckethead on Sat 12/01/2008 17:36:22
Hey,

I want to make a puzzle similiar to the one with the green triangle in openquest. Now I know the author of open quest has probably put alot of efford in making this puzzle and showing how to do it.... But I just don't understand how it works. All I can figure out it was the piece of code does... But not why it's written like that.

Could someone provide me a little more info?  :)

Thanks
Title: Re: Triangle puzzle like in openquest
Post by: Galen on Sat 12/01/2008 17:51:58
It basically checks if the peices are close to where they should be coordinate wise.
Title: Re: Triangle puzzle like in openquest
Post by: Buckethead on Sat 12/01/2008 18:10:19
I know what it does. But I have no idea how to do it myself.  :(
Title: Re: Triangle puzzle like in openquest
Post by: Galen on Sat 12/01/2008 18:17:18
Hmm.... I can't see a simpler way to teach you rather than using the OpenQuest.
Title: Re: Triangle puzzle like in openquest
Post by: Khris on Sat 12/01/2008 19:39:14
Oh my. I've taken a look at the code and while it's solid it's also done in the probably most unwieldy way imaginable.

So, you figured out what the code does but not why it's written like that? I'm not following you. Are you talking about the necessary "any click on object" events? ???
Title: Re: Triangle puzzle like in openquest
Post by: Giddy Plant on Sat 12/01/2008 20:45:48
The author of the "unwieldy way" was me, and yes it is. There's no need to do it all manually like that but it got the job done at the time!
Title: Re: Triangle puzzle like in openquest
Post by: Buckethead on Sun 13/01/2008 09:49:52
Well I know what the codes does because they have green lines of comments but for the most part I'm clueless on how to make this puzzle myself.  ???
Title: Re: Triangle puzzle like in openquest
Post by: Khris on Sun 13/01/2008 15:48:11
Ok, I'll try to break it down for you:

- the puzzle pieces are objects. GI 13 is used to store which piece is currently attached to the mouse; if it's 0, no piece is attached.

- every object/piece has its on click event set to do the following:
if (GI 13 == 0 [no piece attached]), set GI 13 to the clicked object's number and the object's baseline to 200 so it's displayed above all other objects
if (GI 13 != 0 [object x is attached]), set GI 13 to 0 i.e. drop the piece. Compare it's current position to the target position and move it there if it's in the vicinity.

- the room's rep_exe centers the currently attached piece (if there is one/GI 13 != 0) at the mouse's coords. This also makes sure that if a piece is attached, the player can only click that piece, none other, which'll result in it being dropped.

So far so good.

As for doing that puzzle yourself, add the pieces as objects to your room.
Then add the elements from the OpenQuest room script to your own room.
Alternatively, copy the room to your own game and reset the sprites of the objects.
If you want to use fewer pieces, you're fine, just delete the superfluous objects.
If you want to use more pieces, add the "any click" event to each new object.
Title: Re: Triangle puzzle like in openquest
Post by: Buckethead on Sun 13/01/2008 16:06:15
Thanks, I think I get it now  :D

Will be some trial and error to get it right but I think I see how it works now  :)