Missing function: GetRoom?

Started by stuh505, Sun 18/04/2004 06:21:43

Previous topic - Next topic

stuh505

funny, this function doesn't exist?

come on, there MUST be a function that returns the number of the current room...why it isn't called GetRoom I don't know, but it's not listed under room functions in the manual...I don't allow myself to believe that such an important function doesn't exist...

(I need this because I've got an inventory item that teleports you to a room when you look at it and you need to be able to return to whatever room you came from...could be called from anywhere)

Bryan

You might be interested in the following global variables:

character[ID].room
character[ID].prevroom
this space intentionally left blank

stuh505


Pumaman

Yeah, I appreciate this isn't the most obvious thing in the world, but:

character[GetPlayerCharacter()].room

will always give you the current room number :)

stuh505

Yeah, a bit less intuitive, but one advantage I just discovered to this implementation is that it allows me to manually change the room//prevroom variable without actually loading a new room which is imperitive in my case, so don't take away these variables in the next version or anything :P

Ishmael

Removing something so commonly used would crash some long-term projects, like mine, since the creation spans over several versions, if a function used in the game is removed from the engine, it will automatically cause problems and extra work to the creators ;)
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Gilbert

Heh no one was saying to remove the variables, they always work that way. In case you really want a function like implementation (just for the readibility of codes maybe) just define a function like:
function GetRoom() {
  return character[GetPlayerCharacter()].room;
}

in the global script and then import it in the script header:
import GetRoom();

stuh505

Well I know Pumaman is continually revising this thing, so when he admits something is unintuitive I think it is logical to assume that he might possibly consider rethinking the implementation of it...now that I know, I don't care what the function looks like...it's just a matter of changing the learning curve for new users.  Thank you Gilbot on that tutorial for how to write a function  :P

Audiomaster

Hello,

Quoteimport GetRoom();

doesn't work on my system, but

Quoteimport function GetRoom();
does. Is it right anyway?

Best regards from northern Germany
michael

Rui 'Trovatore' Pires

Well, I wouldn't say it's unintuitive. It's documented, along with a bunch of other variables that everyone should browse through before really trying to script their way through AGS.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Kweepa

I'm curious to know why it's imperative that you manually change the room/prevroom variables!
Sounds dangerous.
And likely to break in future versions - they're not guaranteed to stay as you've set them.
Why not use a global variable instead?
Still waiting for Purity of the Surf II

stuh505

Sure Steve, if you can think of a cleaner implementation I'd be happy to hear it.

I am using room properties to record the type of each room.  There are 3 types; walkable rooms, item closeups, and room closeups.  

My inventory system is a little different; bringing up the inventory shows the selected inventory object in the corner of the screen, with "1/3" or whatever written below it to indicate how many total items there are.  The player can cycle through the inventory, or use the selected item.

On certiain items, "using" the item shows them a closeup of the item, which is actually taking them to a new "room".  Then, when they stop looking at the item, I load the room stored in the prevroom global variable.

However, when a character stops looking at a closeup of a part of the room, I also return them to the main room by loading the room stored in prevroom.  

I have chosen this modular approach to returning to the walkable room rather than individually scripting this functionality over and over for each room, because that would be unneccessarily  tedious and confusing code.

So, this is all well and good until the player decides to look at their inventory while they are in a room closeup.  Because when they stop looking at the item, they will return to the room closeup...and when they are done looking at the room closeup, they will be returned back to the inventory closeup.  Doh!

To solve this problem, whenever the player decides to go in for an inventory closeup while they are already in a room closeup, I overwrite the current room variable with the prevroom variable.  That way, when they return from looking at the inventory closeup, they will return to the walkable room.

Honestly, I can't think of a cleaner way to do this.  I could use more variables but it would only confuse the code...and I doubt that this would cause any unexpected bugs.  (although, I admit that bugs wouldn't exist if they were expected :P)

Pumaman

Quote from: TK on Tue 20/04/2004 11:01:39
Removing something so commonly used would crash some long-term projects, like mine

Don't worry, removing them is not even being considered - those variables are very useful for various tasks and it would be silly to remove them.

What I am considering though is a way to better document the way to get the current room (perhaps an entry in the Beginner's Tech FAQ would be good), or perhaps to add a GetCurrentRoom function, just to make things clear.

SMF spam blocked by CleanTalk