Using GetInt to return as part of another function?

tbworld

Hi Ya'll, new to Quest here, i've put about 30 hours or so into it so I know my way around. I know a few other coding languages from which I draw my knowledge and I am trying to do something but am not sure if A. its possible and B.what the correct syntax is.

I am trying to write a universal Run command where the user types "run" and they return to the room they were previously in. Im sure there's a more streamline way to do this but the way I went about this is to create an object called PreviousRoom with an attribute called PreviousRoomNumber. Every time the player exits a room, the PreviousRoomNumber updates to the number of the room they are exiting. (my rooms are named: Room 1, Room 2, Room 3, etc)

The problem occurs when I try to call upon this attribute. Right now, my code reads:

MoveObject (player, Room [GetInt(PreviousRoom,"PreviousRoomNumber")])

using [] was just a guess I had from the other languages that I know. Could anyone help me out with the correct way to right this?


Jay Nabonne

You could try:

MoveObject(player, GetObject("Room " + PreviousRoom.PreviousRoomNumber))

It would be helpful to know how you're setting PreviousRoom.PreviousRoomNumber. (And you don't have to create a new object for this. You can easily use hang the PreviousRoomNumber attribute off the game or player object, if you wish.)


tbworld

Ah! wasn't aware i could throw an attribute into the game. But obviously that would be a much more streamline method :)

At the moment i'm just manually writing the script into each exit using "run a script on exit" using

'''set (PreviousRoom, "PreviousRoomNumber", 1)'''

where the room number is currently 1 (but would be whatever the current room number is)


tbworld

Your adjustment worked perfectly thank you!


OurJud

Will this allow the player to retrace their steps indefinitely, or is it just a 'one step back' thing?


Jay Nabonne

There's just one variable, so only one step. And since it bypasses the exit when you "run", I assume you can only run once and then that's where you are (since you're then in the previous room).


OurJud

I was looking at doing something similar for my last game, where the player typed 'back' to exit a room and return to their previous location, but I never quite got there.


TinFoilMkIV

@tbworld I put together something similar to this not too long ago but whether it does what you want depends on the specifics of how and when this function is coming into play. If you're willing to share a bit more of the details I can probably help work out some of the specifics.

Edited for clarity


OurJud

Not sure who you're addressing, TinFoil (I assume the OP) but in my case I was just looking for an easier way to switch back and forth between rooms.


TinFoilMkIV

Yea was directed at tbworld, just realized I didn't actually specify that anywhere, so edited.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums