3x3 box puzzle

Started by Jordanowen42, Sun 29/09/2024 06:59:25

Previous topic - Next topic

Jordanowen42

Hello all-

I'm working on a puzzle for my game where the player is presented with a 3x3 grid of boxes into which blocks must be inserted in a specific order to advance. So I need each of the blocks (which are contained in the inventory) to be able to be inserted into all nine of the boxes so that the player can try different combinations. I was originally going to make each other boxes a hotspot and have nine invisible objects contained in each of them. The objects in each box would then become visible as the player used the corresponding inventory item on them. This ended up not working because it exceeded the game's limit of 40 items per room. Does anyone have any suggestions? I am very much a novice so some code would definitely help.

Kind regards,
-Jordan

RootBound

#1
There are multiple ways to do it, but you should only need nine objects. You can change each object's graphic depending on which inventory is used on it, and check each object's graphic when looking for the right combination.

You could also make the puzzle a GUI and use buttons instead of objects, and change each button's graphic. It's up to you.

But ultimately, you only need to check for which graphic is used, which can be done with simple if statements like
Code: ags
 if (oBox2.Graphic==6){
  //code here
}
It's still a lot of interactions but it at least simplifies the number of objects you need.

There are ways to simplify the number of interactions too, but someonecelse can probably explain that more efficiently than I can. this should at least get you started.
They/them. Here are some of my games:

eri0o

Is this grid of boxes something that is presented as a zoom in of something that is shown in not close-up view before, and then once you click you enter in "puzzle-mode" or more like something in the room, where the player has to walk around to place big objects? I think the visual design can orient to either a GUI or a Room implementation.

Are the objects inserted in the grid using the same sprite as when they are in the inventory or do they have specific sprites for each, or even a specific sprite for each grid position and a single sprite for when they are in the inventory?

The general idea is you will need to remove the inventory when placing the object and look at the piece and then retrieving the appropriate inventory item to the player if they pickup such item back.

There are many ways to go here, but you probably only need 9 elements switching their sprites.

Ah, also the room object limit should actually be 256 objects unless you are not using the latest stable release

heltenjon

Quote from: Jordanowen42 on Sun 29/09/2024 06:59:25This ended up not working because it exceeded the game's limit of 40 items per room. Does anyone have any suggestions? I am very much a novice so some code would definitely help.
Quote from: eri0o on Sun 29/09/2024 13:44:55Ah, also the room object limit should actually be 256 objects unless you are not using the latest stable release

If you are working using an older AGS version and what you need is to increase the number of objects, then a workaround is to use characters instead of objects. (I think the suggestions already made are better, though.)

Crimson Wizard

#4
I suppose this should be obvious from the answers above, but to reinstate just in case: same object (character, etc) may be reused and play multiple roles in game. This is achieved by changing its looks and other properties.

Therefore, when you have a case when you need too many different variations of objects, create only number of objects that can be in play simultaneously, and configure them to represent different roles depending on situation.

Same object in 1 cell may display unlimited amount of items by changing its graphic.
Same character may play unlimited amount of random NPC variations passing by.
and so on.

Other than that, if you actually DO need a lot of objects on screen at once:
- AGS 3.6.1 and higher supports up to 256 objects per rooms
- Characters are unlimited and may serve as a workaround for objects, when you need them to have interactions. Also character may be moved to other rooms, so this prevents having to create same set of objects in all rooms, if you need to repeat certain things there.
- Overlays are unlimited and created right in script. They are a good choice when you need only visual representation (they do not detect clicks on them).

What else to say...
If the proposed way to detect the "role" or "meaning" of object by comparing its Graphic is not suitable or not convenient, there's also "Custom Properties" - these are values that may be "attached" to an object:
https://adventuregamestudio.github.io/ags-manual/CustomProperties.html

Rik_Vargard

I'm working on a similar puzzle right now. 3x3 grid and the objects have to be placed in a certain way.

ex: Object 1 has to be placed first, object 5 has to be second and object 9 has to be third. Other combinations will not work.
When you click on an object, it changes the Graphic (oObject1.Graphic = 1;) etc.
Then I give points when clicking on the right buttons in the right sequence.
When I click on the confirm button, I check if the score is right.
To make sure the player has pressed 1 , then 5 and then 9, I verify the score, like:

Code: ags
// clic button 1
function obtn01_Interact(Object *theObject, CursorMode mode)
{
  aBlip.Play();
  if (obtn01.Graphic == 2908)
  {
    obtn01.Graphic = 2909;
    Points35 += 50; ///////////////// THIS!
    oConfirm.Visible = true;
  }
}
// click button 5
function obtn05_Interact(Object *theObject, CursorMode mode)
{
  aBlip.Play();
  if (obtn05.Graphic == 2908)
  {
    obtn05.Graphic = 2913;
    if (Points35 == 50) Points35 += 50; //// if first button is right, points up
    oConfirm.Visible = true;
  }
}
// click button 9
function obtn05_Interact(Object *theObject, CursorMode mode)
{
  aBlip.Play();
  if (obtn09Graphic == 2908)
  {
    obtn09.Graphic = 2917;
    if (Points35 == 100) Points35 += 50; // if second button is right, points up
    oConfirm.Visible = true;
  }
}


Every other button gives Points35 += 1;

When I click on Confirm and I have 150 points the puzzle is solved.
Else, the puzzle resets.

Jordanowen42

Quote from: eri0o on Sun 29/09/2024 13:44:55Ah, also the room object limit should actually be 256 objects unless you are not using the latest stable release

How do I change the number of objects?

Snarky

Quote from: Jordanowen42 on Tue 01/10/2024 05:39:21How do I change the number of objects?

You don't have to because the solutions to your problem only require 9 objects at most. Please don't implement your original idea of using 81 different objects.

Jordanowen42

Hello all-

I figured it out and it was staring me right in the face the whole time: what I needed to do was create nine invisible objects and then simply have the graphic change to a different item number in the cache based on the corresponding inventory item being inserted into the slot.

Thanks for all the great ideas tho.
-J

Snarky

#9
Quote from: Jordanowen42 on Tue 01/10/2024 07:30:08Thanks for all the great ideas tho.

 ???
What you ended up doing was literally the first thing anyone suggested:

Quote from: RootBound on Sun 29/09/2024 11:35:16There are multiple ways to do it, but you should only need nine objects. You can change each object's graphic depending on which inventory is used on it

In any case, now I feel more comfortable answering your earlier question:

Quote from: Jordanowen42 on Tue 01/10/2024 05:39:21How do I change the number of objects?

You update AGS to the latest version and use that version to edit your project.

Jordanowen42

Quote from: Snarky on Tue 01/10/2024 08:04:20
Quote from: Jordanowen42 on Tue 01/10/2024 07:30:08Thanks for all the great ideas tho.

 ???
What you ended up doing was literally the first thing anyone suggested:

Quote from: RootBound on Sun 29/09/2024 11:35:16There are multiple ways to do it, but you should only need nine objects. You can change each object's graphic depending on which inventory is used on it

Ah so it was! My oversight is shameful. Thank you all for the help regardless.

SMF spam blocked by CleanTalk