Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Kirinin on Fri 08/05/2009 04:28:51

Title: 'Zooming In' on objects, then having them disappear from main room? [SOLVED]
Post by: Kirinin on Fri 08/05/2009 04:28:51
Hi, all!  This is the first time I've programmed since using BASIC, so I could really use some help.  I have already looked here:  gamedesign.edublogs.org/files/2009/02/ags-tutorial.doc and in the AGD basic tutorial as well... but no luck as of yet.

My goal is to 'zoom in' on a dresser in Room 1 and have the main character take a vase of flowers and a hand mirror from said dresser.

More info:

a) I have made two separate rooms already, one the regular room, one the 'zoomed-in' image.
b) Even in Room 1, the vase of flowers and hand-mirror are objects; it's just that when you interact with them, I've coded:

function ovaseflos_Interact()
{
  cEgo.Walk(297,  222, eBlock);
  cEgo.FaceLocation(300, 125);
  Wait(40);
  cEgo.ChangeRoom(2);
}

...so that whether you touch the dresser (a hotspot) OR either object on said dresser, the same thing will happen... the player will go to the 'close-up'.

c.  When you get to the close-up (Room 2), the vase and mirror are still coded as objects, but they are coded differently from the same two objects in Room 1.


I have two questions:

1) How can I make sure that the objects have 'still' disappeared when the player returns to Room 1?

2) What is a good/intuitive way to get the player back to the main room after they've picked up all the items? 

This is probably way too detailed, but I've been on a few forums before, and it seems like the more specific you are, the more likely you are to get an answer.

Thanks to anyone who's read this far!  I would appreciate any help you all could give me, even if it's just a link to a tutorial that might help.   ;D

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Trent R on Fri 08/05/2009 06:30:38
If I understand your question correctly, then the answer is easy.....

Variables!!!!

Lemme see if I got the scenario right: Click on objects in Room1, it zooms in on the to room2, pick up the zoomed objects and they disappear, when you go back to room1 the objects are gone. Right?

I'd suggest using any of Global Variables, Game.DoOnceOnly, and/or player.HasInventory. For example:
//Room2 object interaction
function oZoomMirror_Interact () {
  player.AddInventory(iMirror);
  oZoomMirror.Visible=false;
  if (oZoomVase.Visible==false) ChangeRoom(1); //this will provide the auto changing if you've gotten both items
}

//Room 1 Before Fade-in
function room_load() {
  if (player.PreviousRoom==2 && player.HasInventory(iMirror)) oMirror.Visible=false;
  if (player.PreviousRoom==2 && player.HasInventory(iVase)) oVase.Visible=false;
}


As I was typing the code above, I got some ideas on how (in my opinion) to best do it, and added some other commands. Read the manual entries to understand them (HasInventory, PreviousRoom, Operators, etc)
Also, don't forget that you can't just copy and post the entire code and expect it to work. You have to link the functions via the Events Pane (the lightning bolt)

And lastly, this is just how I would do it. There's plenty of ways to script each problem, and some may work better for you.


~Trent
PS-Welcome to the Forums!!
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Fri 08/05/2009 07:15:43
Yes, that's it exactly, and I was trying to envision an if-then scenario, but I just plain hadn't seen anything like that done, yet, in what I'd read.

Thank you so much - off to see how that works!

And thanks also for the welcome.  Glad to be here!  :)

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Fri 08/05/2009 07:39:51
Actually, does it matter if the previous room was Room 2?  So long as they have the inventory item, said item shouldn't be displayed, no matter how long ago you were in that room!  Can we get rid of that bit of code?

This is what I've got right now, but the computer won't even run it:

function room_load()
{
  if (cEgo.HasInventory(imirror) omirror.Visible=false);
  if (cEgo.HasInventory(ivaseflos) ovaseflos.Visible=false);
}

It keeps on saying "expected semicolon after ')'".  But when I try to put one there, it actually STILL says that.

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: GarageGothic on Fri 08/05/2009 07:51:36
It's because the parenthesis is placed wrongly (yeah, the message is a bit misleading). It should be:


function room_load()
{
  if (cEgo.HasInventory(imirror)) omirror.Visible=false;
  if (cEgo.HasInventory(ivaseflos)) ovaseflos.Visible=false;
}
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Fri 08/05/2009 07:57:51
Once I did that, the code on room 1 was fixed... but it didn't accept the code for Room 2.  It said both of them had 'undefined ifs' or something similar.

I thought perhaps I didn't need them because if the player has them in inventory, the player has them in inventory, right?

Nope.  Back to square one.  We have working code in Room 1 - or at least, code that didn't stop the game from playing - but when you return to room one, there are the vase and mirror.

Mocking us, I think.

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Khris on Fri 08/05/2009 08:57:41
Is the player able to leave the close-up without having picked up both items?
Cause if he isn't, you don't need to check the inventory:

// non-close-up room script

function room_load() {
  if (player.PreviousRoom == CLOSE_UP_ROOM) {
    oVase.Visible = false;
    oMirror.Visible = false;
  }
}
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Fri 08/05/2009 15:07:28
The player can leave the close-up at any time.  Moreover, they can return to the close-up to once again view that there is nothing sitting atop the dresser anymore. 

In regards to my second question:
I made the area surrounding the dresser a hotspot, so that when the player clicked on the wall (i.e. - not the dresser) it would return the player to the main room.  I played with having a little hotspot with the words 'Back Off!' on it, returning the player to the main room, but it was just plain too intrusive.

I sure hope you guys continue to have new ideas!  Meanwhile, I will dive into code.   ???

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Hudders on Fri 08/05/2009 15:22:53
Quote from: Kirinin on Fri 08/05/2009 07:57:51
but it didn't accept the code for Room 2.

What is the code you've got for Room 2?
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Fri 08/05/2009 15:36:15
I was using what Trent T had recommended.

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Hudders on Fri 08/05/2009 16:16:44
TrentR didn't suggest anything for Room2's room_load function.

What do you mean when you say that it didn't accept the code?
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Fri 08/05/2009 16:33:37
Quote from: Hudders on Fri 08/05/2009 16:16:44
TrentR didn't suggest anything for Room2's room_load function.

You're right!  I started this post VERY late last night, and cut-and-paste code without thinking too clearly about it, I suppose.  Neither suggestion for either room worked.  I went back to the code for Room one and changed it to get rid of the

if (player.PreviousRoom==2 && player.HasInventory(iMirror) oMirror.Visible=false;

and changed it to

function room_load()
{
  if (cEgo.HasInventory(imirror) omirror.Visible=false);
  if (cEgo.HasInventory(ivaseflos) ovaseflos.Visible=false);
}

...because I figured no matter what room the player had been in, if the objects are in his inventory, he shouldn't still see them sitting on the dresser!

Then I fixed the parentheses so that it looked like this:

function Room_BeforeFadeIn()
{
}
function room_load()
{
if (cEgo.HasInventory(imirror)) {omirror.Visible=false;}
  if (cEgo.HasInventory(ivaseflos)) {ovaseflos.Visible=false;}
}

The computer will run the game with this code intact as it is, but it doesn't do the job.  BTW, in case this is just in the wrong place (? - global script?) that code is in the Room 1 (non-close-up) room.

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Fri 08/05/2009 16:42:52
Just a general thanks to everyone who's helped me with this - it's taking a bit longer than I'd thought, and I appreciate your time and energy.  :)

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Hudders on Fri 08/05/2009 16:58:27
Your code should work. As I understand it, when the mirror and vase of flowers are in the player's inventory, (after he picks them up in Room 2, (close-up room)), then in Room 1, (non-close-up room), they won't be visible.

If you set the two objects so that the player starts with them, what happens in Room 1?
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Fri 08/05/2009 17:04:14
That's clever; let me check.

Er... nothing whatsoever changed, except that if you look in the characters' inventory, there they are.  Same exact thing: they are present there on the dresser, you can go to the close-up and pick them up, they disappear from the close-up, they are still present when you back up to Room 1.

*le sigh*  I was hoping my code there was just wrong...  Instead, this is a more subtle problem...

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Trent R on Fri 08/05/2009 17:15:08
Ah, sorry about the wrong parenthesis. That's what happens with you try to write code straight into the reply box (I usually find it easier to open up AGS, cause then I have manual access too). Fixed my previous post.

Why do you have both a Room_BeforeFadeIn() function and a room_load() function? Also, did you link the function with the lightning bolt and the (...) button?


~Trent
PS-You can format code for the forums by putting them inside [ code ] [ /code ] tags (removing the spaces first, of course)
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Fri 08/05/2009 17:47:14
Yeah... er, no reason (*swiftly deletes*).  It's probably because I was trying so many different things, one part got 'left behind'.  ;)

Do you mean the events button for the items in Room 1?  If I go to 'events' for the items in Room 1 (non-close-up) then the character will be able to pick them up without going to the close-up (Room 2).  Right now if the player clicks on the flowers or the mirror from far away, it takes you to Room 2.

-K

P.S. - Don't worry about the parentheses.  I got there... on to the next bug!

Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Sat 09/05/2009 02:57:11
Er... I realize now that last P.S. sounded unclear.  I meant I fixed the parentheses!  I'm definitely still having the same issue...  :(

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Hudders on Sat 09/05/2009 10:05:10
I created a game using the same code and you're right, it doesn't seem to be firing the room_load() function at any point.  :-\ I have no idea why that would be doing that.
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Khris on Sat 09/05/2009 11:26:49
Is the function linked to the room's event...?
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Sat 09/05/2009 14:26:15
This is what Trent asked, and I think this might be the problem.  In room 1, when you click 'interact object' it takes you to the close-up (room 2).  If I want things in room 1 to disappear when something is taken from room 2, to what event should it be linked?

???

-K
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Khris on Sat 09/05/2009 18:00:24
You're looking for the room event "player enters screen (before fadein)".
Title: Re: 'Zooming In' on objects, then having them disappear from main room?
Post by: Kirinin on Sun 10/05/2009 03:17:36
I wish there were an emoticon actually capable of expressing the joy that I feel at FINALLY having this resolved - I can't believe it was something so simple!  THANK you!

;D     ;D     ;D


-K