Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: salma on Tue 15/01/2008 14:29:04

Title: Hidden object games
Post by: salma on Tue 15/01/2008 14:29:04
Can AGS be used to make a simple "hidden object" game?
Title: Re: Hidden object games
Post by: Galen on Tue 15/01/2008 16:23:19
Yes.
Title: Re: Hidden object games
Post by: salma on Tue 15/01/2008 17:11:38
Lets say I want to add several objects to a room,and have them disappear when clicking on them.
when all the objects are cleared from the screen(in no particular order) a message appears, or the player moves to another room...I also would like to add a list of the objects names,and have the name of any object disappears from the list at the same time the object it self is removed from the room.
Can this be done just by using room editor and object's properties?or do I need scripting for that?
Can you point me where to start?if there is any tutorial would help with scripting?
I did finish the beginner's tutorial and scripting tutorials at the AGS site.
Title: Re: Hidden object games
Post by: Khris on Tue 15/01/2008 17:30:51
You'd have to add an on_mouse_click function to the room, like this:

// room script

#define OBJECTS 10;        // ten objects

String[OBJECTS];

function print_list() {
  DrawingSurface*ds = Room.GetDrawingSurfaceForBackground();
  ds.DrawingColor = Game.GetColorFromRGB(255, 255, 255);  // white background
  ds.DrawRectangle(220, 0, 319, 199);  // clear rightmost 100 pixels

  ds.DrawingColor = Game.GetColorFromRGB(1, 1, 1);  // black text
  int i;
  int y=20;
  while(i<OBJECTS) {         // draw objects' descriptions
    if (String[i].CompareTo("")!=0) {
      ds.DrawString(225, y, Game.NormalFont, String[i]);
      y+=15;
    }
    i++;
  }
  ds.Release();
  if (y==20) player.ChangeRoom(5);     // ADDED THIS LINE
}

function on_mouse_click(MouseButton button) {
  if (button!=eMouseLeft) return;            // only continue if left mouse button was pressed
  if (GetLocationType(mouse.x, mouse.y)!=eLocationObject) return;  // only continue if user clicked an object
  ClaimEvent();     // stop global script from handling the click

  Object*o = Object.GetAtScreenXY(mouse.x, mouse.y);
  o.Visible=false;              // make object disappear
  String[o.ID] = "";           // remove text
  print_list();                    // update list of objects
}


Now add a RunScript action to the "player enters screen (before fadein)" event, then put this inside the function:

  int i;
  while(i<OBJECTS) {
    String[i] = object[i].Name;       // set the list strings to the objects' names
    i++;
  }


You don't need properties, just enter the names of the objects as their in-game names. (Not the script names, you can leave those blank.)

I've used draw functions to display the list. You can use a GUI with a ListBox instead. However, in this case removing the entries requires a bit work, since the entries are renumbered from 0-x each time an entry is removed.

Edit: added check for all objects having been found (see end of print_list function)
Title: Re: Hidden object games
Post by: OneDollar on Tue 15/01/2008 20:02:51
KhrisMUC's method is a fancy and arguably better way of doing things, but you could set everything up manually if you're finding the code a bit hard to follow.

First draw your background complete with an empty list down the side. Then draw the graphics for the objects that will be hidden in the room. Then make graphics for the list names of the objects, one with just the name and one with the name crossed out.

Say you want to find a ball hidden in the room. Make a new object called oBall and give it a sprite with a picture of a ball. Place it somewhere in the room. Make another object called oBallList and give it the sprite you drew with the text "ball", and place it somewhere on the list.

At the top of your room script make two new variables to hold the total number of objects and the number of objects the player has found
// room script file
int TotalObjects=10;  //set the total number of objects in the room to 10
int FoundObjects=0;  //make a variable for the number of found objects (initially 0)


Now make a new function for any click on the object and write something similar to the code below in it:
function oBall_AnyClick()
{
  oBall.Visible=false;  //hide the ball (make it look like its disappearing)
  GiveScore(1);  //add one to the player's score
  oBallList.Graphic=1;  //set the ball's list entry graphic to the number of the one with 'Ball' crossed out
  FoundObjects++;  //add one to the number of found objects
}


Finally in the repeatedly execute function of the room's script add
function room_RepExec()
{
  if(FoundObjects==TotalObjects){  //if the number of objects found equals the number of objects hidden
    player.ChangeRoom(1);  //go to room 1
  }
}


Of course you'd have to add similar AnyClick code to every object, and setup the variables and RepExec code for every room using this method.

This is a simple and rather bad way of doing it, repeating far too much code, needing too much put in by hand and it won't allow you to monitor anything globally or change the objects that are hidden in rooms etc, but it should get you off to a bit of a start if you're just starting out coding and Khris' draw functions look a bit scary.

Next step would be to start putting things in a global script, and building only one global function that would deal with the removing, crossing out and scoring of clicking on objects.

In short, yes it can be done and it would be much easier using scripting. Its a while since I used the interactions editor, so I'm not sure if this is the sort of thing you could do in it, but you'd be following a similar method if you could. (Even if you can use the IE, you should learn to script it ;))
Title: Re: Hidden object games
Post by: salma on Wed 16/01/2008 09:20:38
Thanks to everybody for these responses,
OneDollar, what you said makes since to me:)
But it seems to me that scripting is the way to go, so I think I'll have to pursue the way KhrisMUC mentioned.
Scripting is something that I'll have to learn sooner or later, specially since I would like to have more freedom creating puzzles.

Thanks again Crazy,KhrisMUC and OneDollar
Title: Re: Hidden object games
Post by: mawilbolou on Wed 04/12/2024 09:38:08
@OneDollar
If I use your code above and place objects
I get this error.

The game is set to start in room -1 which does not exist
Is there any way to change this?
I looked through Default and General settings.
Title: Re: Hidden object games
Post by: Khris on Wed 04/12/2024 11:32:18
The error is unrelated to OneDollar's code.

If you started from a template that doesn't have any characters, create a new character (which will become the player character by default). Then set this character's starting room to 1 (or whatever the first room of your game is supposed to be.)

(AGS is room-based and needs to know in which room to start the game, and also which character to use as player. This is a requirement to run any game. Switching to another room is done by having the player character change to that room, or by setting another character currently residing in another room as the active player character.
Another way to look at this is AGS will always display the room to the user that is stored in player.Room, so player cannot be null, and player.Room must be a valid room number.)
Title: Re: Hidden object games
Post by: mawilbolou on Wed 04/12/2024 20:59:01
@Khris ah great thank you. 
Title: Re: Hidden object games
Post by: mawilbolou on Fri 06/12/2024 08:18:47
Does anyone know how to set the player.room to be set to 1?
I found this...
Room.Exists
static bool Room.Exists(int room)
Returns true if the specified room exists in the game.

Example:

if(Room.Exists(10))
{
    player.ChangeRoom(10);
}
If room 10 is valid, go to that room.

Not sure if this will do it?
Title: Re: Hidden object games
Post by: Snarky on Fri 06/12/2024 09:14:35
Why don't you try it?
Title: Re: Hidden object games
Post by: Crimson Wizard on Fri 06/12/2024 09:30:35
You don't have to use Room.Exists though, simply use player.ChangeRoom(N).
Title: Re: Hidden object games
Post by: Crimson Wizard on Fri 06/12/2024 09:31:36
Wait, are you speaking about starting room? If so, then you must do that in the Editor.
Open the player Character, and set StartingRoom property in the Property Grid.
https://adventuregamestudio.github.io/ags-manual/EditorCharacter.html
Title: Re: Hidden object games
Post by: Khris on Fri 06/12/2024 11:32:49
player.Room is readonly.

Since I already explained in detail how to fix the issue, let me quote myself:

Quote from: Khris on Wed 04/12/2024 11:32:18If you started from a template that doesn't have any characters, create a new character (which will become the player character by default). Then set this character's starting room to 1 (or whatever the first room of your game is supposed to be.)
Title: Re: Hidden object games
Post by: eri0o on Fri 06/12/2024 12:32:25
So I really would like to have a button on the room editor so one can just click and put the player character somewhere there - like it is done in rpg maker.

(https://user-images.githubusercontent.com/2244442/88409453-819c2700-cdc4-11ea-836b-51395f17fc2b.gif)

I feel it would just be easier, specially when testing. This is other thing, a run button that means "Run this room", AGS has a command line argument for this already to set the starting room.
Title: Re: Hidden object games
Post by: Crimson Wizard on Fri 06/12/2024 12:34:12
Quote from: eri0o on Fri 06/12/2024 12:32:25So I really would like to have a button on the room editor so one can just click and put the player character somewhere there - like it is done in rpg maker.

Such button may be a good thing, it's going to be pretty explicit too.
OTOH, what about drag & drop Character from the project explorer?
Title: Re: Hidden object games
Post by: eri0o on Fri 06/12/2024 12:43:11
Other possibility would be a context menu, but it may be harder to find it when starting out.

(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTf-8RvP1M02LM3vVfA5g5l3X9dnkH9i386zO1L4H9DLegqxSTdbCs1hFfw&s=10)

About dragging and drop it would be nice if it works but discoverability will be low since we don't support many dragging and drop interactions as far as I remember. Not sure there are many other opportunities, it would be nice if we could figure a list of possible drag and drop operations.
Title: Re: Hidden object games
Post by: mawilbolou on Sat 07/12/2024 10:48:18
Quote from: Khris on Fri 06/12/2024 11:32:49player.Room is readonly.

Since I already explained in detail how to fix the issue, let me quote myself:

Quote from: Khris on Wed 04/12/2024 11:32:18If you started from a template that doesn't have any characters, create a new character (which will become the player character by default). Then set this character's starting room to 1 (or whatever the first room of your game is supposed to be.)

Thanks for the suggestions and comments everyone.

@Khris sorry I completely misread the first part of your comment about character start room.