Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: OldTimeGamer on Fri 11/03/2016 16:50:32

Title: How to script a puzzle
Post by: OldTimeGamer on Fri 11/03/2016 16:50:32
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
Title: Re: How to script a puzzle
Post by: Danvzare on Fri 11/03/2016 17:00:55
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) Select
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.
Title: Re: How to script a puzzle
Post by: Danvzare on Fri 11/03/2016 17:01:53
Please delete this post, I accidentally pressed the wrong button.
Title: Re: How to script a puzzle
Post by: [delete} on Fri 11/03/2016 17:15:55
Please delete mine too, I accidentally pressed the wrong button as well.
Title: Re: How to script a puzzle
Post by: OldTimeGamer on Fri 11/03/2016 18:22:46
Thank you very much for your help. I think you explained it well.

Have a nice day :)
Title: Re: How to script a puzzle
Post by: Grok on Sat 12/03/2016 06:36:00


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);
}

Title: Re: How to script a puzzle
Post by: 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?

Title: Re: How to script a puzzle
Post by: Danvzare on Sat 12/03/2016 14:47:58
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