How to go about scripting a connection puzzle.

Started by Samwise89, Wed 22/06/2011 01:18:58

Previous topic - Next topic

Samwise89

Hi, another question!

I'm trying to create a connection, so i want the user to click and an area and then if he clicks in the right area to create a connectiona line showing the connection to appear.

I started out using hotspots, but once i was done with that i realised i have no idea on where to go after this to detect if the next mouse click after the initial correct mouse click is on the opposite hotspot to create the connect, any help greatly appreciated!

monkey0506

Well if you're using hotspots, then it should be pretty simple I imagine:

Code: ags
// room script

bool startedConnection = false;
Hotspot *lastClickedHotspot;

function hConnection1_AnyClick()
{
  startedConnection = true;
  lastClickedHotspot = hConnection1;
}

function hConnection2_AnyClick()
{
  if ((startedConnection) && (lastClickedHotspot == hConnection1)) lastClickedHotspot = hConnection2;
  else startedConnection = false; // in case the user clicked in the wrong order, reset the connection
}

function hConnection3_AnyClick()
{
  if ((startedConnection) && (lastClickedHotspot == hConnection2)) lastClickedHotspot = hConnection3;
  else startedConnection = false;
}

// ...etc.


You could handle any type of drawing or toggle object visibilty or what-have-you within these functions directly, or perhaps in repeatedly_execute. Probably the latter to reset the state if the connection is broken. It's really up to you how you handle that, but a setup like this would allow you to check that the player had correctly initiated the sequence, and verify the sequence of the current and most recently clicked hotspots. I hope that makes sense..I can try to clarify if you need me to.

niyamen

Hello

sorry for my English,
I'm new to the forum, and it's my first question, all others have solved the old topics and looking in the manual, and even helping me with the video tutorials of disming.

I write here to not create another topic with the same question

I'm trying to do this kind of puzzle, but not as something enabled by this, for example a walkable area.

with three hotspots, and as the code is written in the post above, I have to change to make it work?

thank you very much for your time

SMF spam blocked by CleanTalk