Weird String Behaviour on keypad Puzzle

Started by Phonoitypal, Sun 11/02/2024 12:08:05

Previous topic - Next topic

Phonoitypal

Hi !
I'm trying to make a keypad puzzle.
Basically what I've done first, is create a global variable called 'player sequence' with its initial value, as nothing

Then, I made the following code
Code: ags
function room_Load() {
   playerSequence = "";
}

function CheckPassword() {
if (playerSequence.EndsWith("680")) { 
Display("Password Detection works debug thing");
}
else { 
Display("wrong password debug thing!");
playerSequence = "";
}
}





function oObject6_AnyClick()
{
playerSequence = playerSequence.AppendChar('6');
aAkeypad.Play();
}

function oObject1_AnyClick()
{
aAkeypad.Play();
CheckPassword();
}

function oObject3_AnyClick()
{
playerSequence = playerSequence.AppendChar('8');
aAkeypad.Play();
}

function oObject4_AnyClick()
{
playerSequence = playerSequence.AppendChar('0');
aAkeypad.Play();
}



So, each button would add a character to the playersequence string.
The button that has just 'check password' is a button resembling the enter button.

Now, the weird behaviour that im encountering, is for example. if I would add 'string ends with' a repeating number, for example 888, or 000, the code will work without problems.

But : If I add different numbers, such as in my case, lets say, 680, regardless if I press 6 8 0 in order, it still will give the display/debug message as the password would be incorrect !
Im so confused, could anyone give me some insight regarding this matter?



Khris

#1
Add
Code: ags
  Display(playerSequence);
as the first line in your CheckPassword function.
What does it show?

Also note that you can do this:
Code: ags
function keypad_Click() {
  Object* o = Object.GetAtScreenXY(mouse.x, mouse.y);
  if (o == null) return;
  playerSequence = playerSequence.AppendChar('0' + o.ID); // make sure each object ID matches its digit
  aAkeypad.Play();
}

Now paste keypad_Click into each digit button object's event table.

Phonoitypal

Quote from: Khris on Sun 11/02/2024 12:35:57Add
Code: ags
  Display(playerSequence);
as the first line in your CheckPassword function.
What does it show?

Also note that you can do this:
Code: ags
function keypad_Click() {
  Object* o = Object.GetAtScreenXY(mouse.x, mouse.y);
  if (o == null) return;
  playerSequence = playerSequence.AppendChar('0' + o.ID); // make sure each object ID matches its digit
  aAkeypad.Play();
}

Now paste keypad_Click into each digit button object's event table.




regarding the Display part on the first line of the script. for some reason, it seems that it 'doubles' the digits. if i press 6 8 0, it shows as 66 88 00. I'm also making sure I press only once.

Phonoitypal

also used your keypad click function, it works perfectly, but the same problem persists. for some reason, the click registers 2 times at once

Khris

AGS processes both events. For instance when you click something with the interact cursor, it calls the function linked to the interact event, then the one linked to the any click event.

If the function gets called twice, my guess is it's linked twice?

Phonoitypal

Im not really sure. I also encounter this problem if I somehow assign a view (play only once) on an object and make it get triggered via a hotspot click. it behaves like it is clicked 2 times. I tried to change modes (any click or interact with hotspot etc) but it still behaves like i click it 2 times. could it be because I made a global script to change the cursor while hovering over hotspot/objects ?

Khris

Standard click processing will call Room.ProcessClick(). This gets queued however, so if the function is for some reason* called twice, it gets queued twice, and the linked room script function will also run twice I guess.

*faulty logic in the global on_mouse_click will do this for instance

SMF spam blocked by CleanTalk