How to script a puzzle

Started by OldTimeGamer, Fri 11/03/2016 16:50:32

Previous topic - Next topic

OldTimeGamer

Hello,

for some, this may be a stupid question, yet I have not found this anywhere on the internet.
I want to create an easy puzzle, where you click on objects in the right order (basically "PIN code technique").

I would be glad if anyone could help me with this one.
Thank you for your time. Have a nice day.

David

Danvzare

#1
This is just from the top of my head, but how I'd handle it, is that I'd have a variable, let's call it code.
I'd have code set to 0. When you click on the right number (or object), code would be set to 1. Then if you press the next right object, set it to 2, otherwise set it back to 0.

In pseudo code:
Code: ags
code = 0;
if click on object1
{
    if code == 0
    {
        code++;
    }
    else
    {
        code = 0;
    }
}
if click on object2
{
    if code == 2
    {
        code++;
    }
    else
    {
        code = 0;
    }
}
if click on object3
{
    if code == 1
    {
        code++;
    }
    else
    {
        code = 0;
    }
}

That would result in clicking on object1, then object3, then object2 to input the correct code.

I hope that helps.
I'm sure someone else can give a more specific and clearer answer.

Danvzare

Please delete this post, I accidentally pressed the wrong button.

[delete}

#3
Please delete mine too, I accidentally pressed the wrong button as well.

OldTimeGamer

Thank you very much for your help. I think you explained it well.

Have a nice day :)

Grok


Code: ags

int iProgress=0;


function testClicks(int iX)
{

  if (iProgress+1==iX)
    iProgress=iX;
  else
   iProgress=0;

  if(iProgess==3)
... puzzle solved ...


}


function oObject1_Interact()
{
   testClicks(1);
}

function oObject2_Interact()
{
   testClicks(3);
}

function oObject3_Interact()
{
   testClicks(2);
}


OldTimeGamer

Although, I have one more question to Danvzare.

Where do I put this code, and how do I call the global variable from global variables to the script?


Danvzare

#7
Quote from: OldTimeGamer on Sat 12/03/2016 09:28:57
Although, I have one more question to Danvzare.

Where do I put this code, and how do I call the global variable from global variables to the script?

Where you put it is up to you.
Personally, I'd put it in the room script for the room where it takes place, and create the variable at the top of that room script.
If you've made a global variable though, then to call the variable, just write the global variable's name. As far as I can tell, a global variable is called just like a regular variable.


EDIT: I'm guessing you're using Grok's code, and finding that it isn't compiling.
That's because there's a small typo.
  if(iProgess==3)
should be
  if(iProgress==3)

By the way, thanks Grok! :-D

SMF spam blocked by CleanTalk