Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: marypotter3 on Wed 21/09/2011 00:53:22

Title: If I find some objects, the room background can change?
Post by: marypotter3 on Wed 21/09/2011 00:53:22
Hey, first of all, sorry for my awful english. Well, I'm creating a game that, after you find 3 symbols, it needs to change the background of a room. But I have no idea of how I can do it. I've started creating with AGS today, so I'm completely lost.

Thanks!
Title: Re: If I find some objects, the room background can change?
Post by: pcj on Wed 21/09/2011 01:36:39
You can set up multiple background frames (see "Animating background scenes" in the help file) and then use SetBackgroundFrame as needed to switch between them.
Title: Re: If I find some objects, the room background can change?
Post by: marypotter3 on Wed 21/09/2011 01:42:29
Where do I find this help file? Sry for noob questions, I'm new at this...
Title: Re: If I find some objects, the room background can change?
Post by: pcj on Wed 21/09/2011 01:43:26
Press F1 in AGS.  You can call SetBackgroundFrame at any time in script.
Title: Re: If I find some objects, the room background can change?
Post by: marypotter3 on Wed 21/09/2011 01:45:35
But how can I put this background only AFTER finding those symbols?

So, it needs a code? I'm not good with that, what code can I use?
Title: Re: If I find some objects, the room background can change?
Post by: pcj on Wed 21/09/2011 01:47:55
You put SetBackgroundFrame in the function that processes "finding the symbols" - if that means "Look at object" then put SetBackgroundFrame in the associated function for that event.
Title: Re: If I find some objects, the room background can change?
Post by: marypotter3 on Wed 21/09/2011 01:49:42
What code do I use? I really suck at that... ):
Title: Re: If I find some objects, the room background can change?
Post by: marypotter3 on Wed 21/09/2011 02:33:01
Anyone? Any code? Pwease?
Title: Re: If I find some objects, the room background can change?
Post by: pcj on Wed 21/09/2011 02:37:10
It depends on what you mean by "finding those symbols".  If you mean "the character walks up to the object", you can put a region under it and map a function to it, then put SetBackgroundFrame in the function.

It's a mixture of setting up regions/objects and code, so it's hard to provide code that works out of the box unless you give me an idea of what you have so far.
Title: Re: If I find some objects, the room background can change?
Post by: marypotter3 on Wed 21/09/2011 02:43:55
Ok. Is a point-and-click game. First symbol is on the inicial room, the other symbol is in the stairs, and the third is upstairs. The symbols are in the background, they are not objects (because i dunno how to use objects...), and I don't know what are regions either.

The symbols are hotspots, and when you click on them, my code is like:

// room script file

function hSymbol1_Look()
{
Display("It sounds like you've found a strange symbol.");
}

Please help me x_x
Title: Re: If I find some objects, the room background can change?
Post by: pcj on Wed 21/09/2011 02:51:49
So, once you've got the background frames set up it will be like:

function hSymbol1_Look()
{
Display("It sounds like you've found a strange symbol.");
SetBackgroundFrame(1);
}


And you'll need to bind "enters room before fade-in" and specify:
function room_Load()
{
SetBackgroundFrame(0);
}
Title: Re: If I find some objects, the room background can change?
Post by: marypotter3 on Wed 21/09/2011 02:59:28
Still have errors...

(http://i943.photobucket.com/albums/ad279/StarDazzle_2010/whyyy.png)

I really don't get it. ):

Title: Re: If I find some objects, the room background can change?
Post by: pcj on Wed 21/09/2011 03:00:30
You need to set up the background frames first in the room editor.  Look for the Display Background setting to specify a new background.

(http://i.imgur.com/9YTBj.png)
Title: Re: If I find some objects, the room background can change?
Post by: Khris on Wed 21/09/2011 03:06:19
The issue here is that the background should only change after all three have been found.

Here's what you do:
Open the Global variables pane, add an int with name symbols_found and initial value 0.
Now add another one, type bool, name change_bg, initial value false.

Then use this for the hotspots:
function hSymbol1_Look()
{
 if (Game.DoOnceOnly("finding symbol 1")) {      // first time the player looks at hotspot
   Display("It sounds like you've found a strange symbol.");
   symbols_found++;
 }
 else Display("There's nothing else there to be found.");   // every subsequent look at action

 if (symbols_found == 3) change_bg = true;
 if (change_bg) SetBackgroundFrame(1);   // if the current room isn't the one supposed to change its background, remove this line
}


Same for the other two hotspots/symbols, it's important that you use a different string for Game.DoOnceOnly though. Just replace the '1' with a '2' and '3'.

Once you click for the first time on one of the hotspots, the usual message is displayed and symbols_found is incremented by one. If the hotspot was the third and final one, it will be 3 now, so change_bg is set to true.

For the hotspot in the room that's supposed to change its background, we add another line that'll immediately cause that.
Add the "enters room before fade-in" to that room and put this inside the function:

 if (change_bg) SetBackgroundFrame(1);
Title: Re: If I find some objects, the room background can change?
Post by: marypotter3 on Wed 21/09/2011 03:20:53
But, if I click on the symbol that is the third, before the other symbols, the bg still changes! can the player just find the symbols and, when reach 3, then the new area open?
Title: Re: If I find some objects, the room background can change?
Post by: marypotter3 on Wed 21/09/2011 03:33:41
Oh, my mistake, sorry. I didn't put the "if (change_bg) SetBackgroundFrame(1);" on the code. Sorry!

And thank you! You guys helped me a-lot! (:
Title: Re: If I find some objects, the room background can change?
Post by: Khris on Wed 21/09/2011 03:40:14
My mistake, I've corrected the line.