How to enable inventory item to teleport player to new room and return

Started by Zephyr, Mon 21/10/2019 12:04:17

Previous topic - Next topic

Zephyr

Hi Everyone,
             
  I'm trying to script a scenario where the player can look at an inventory item, which will teleport them to a new room (from wherever they happen to be in the game), where a message is displayed and then return to their previous room on mouse click.  I'm tying my poor brain in knots trying to follow the manual and forums!

So far, I have in my room script:
Code: ags
Overlay *clue1Overlay;

function room_AfterFadeIn()
{
         clue1Overlay = Overlay.CreateTextual (107, 114, 200, eFontNormal, 32784, "Blah, blah, blah.");
         Wait (200);
         DisplayAtY (115, "Click to continue.");
}
Overlay *clue1Overlay;

function room_AfterFadeIn()
{
         clue1Overlay = Overlay.CreateTextual (107, 114, 200, eFontNormal, 32784, "Blah, blah, blah.");
         Wait (200);
         DisplayAtY (115, "Click to continue.");
}

and then in Global Script:
Code: ags
function on_event (EventType iClue1_Look());
{
         SetGlobalInt (1, cChristian.x);
         SetGlobalInt (2, cChristian.y);
         cChristian.ChangeRoom (11);}
         {
    if (event == eEventLeaveRoom)
    {
        cChristian.ChangeRoom on_mouse_click (MouseButton button) {
          cChristian.PreviousRoom, GetGlobalInt(1), GetGlobalInt(2);
          return;
    }
}


I'm getting parse error warnings and nothing is working for me right now.  Any and all help appreciated - but PLEASE try to dumb down your replies because I'm a complete NOOB!
Hell, I'm not even sure I've posted this message correctly!  :-[  Thanks All.
<3 Zephyr <3

Matti

Your brackets are all over the place, that may give you an error. But I think you could do this simpler anyway.

Create a look at-function for your item (in the event section of the item's property pane). Then put the changeroom command in there.
Code: ags

function iClue1_Look()
{
  cChristian.ChangeRoom (11);
}


Then, in room 11's code (or some GUI or whatever handles the message) you could put
Code: ags

cChristian.ChangeRoom(cChristian.PreviousRoom);


You would only need to store the character's coordinates if they actually change (i.e. if cChristian is walking around in room 11);

But I think what you're trying to achieve is just that a message (a clou) appears when the player looks at the item. In that case you don't need to change the room at all. All you'd need would be a GUI that appears on screen. Or is there something else happening in room 11 that could not be done in the room the player is in when looking at the item?

Cassiebsg

I'm not  going to analyze your code, cause my coding skills aren't that advance and I don't really "know what you have coded"... can you even type this? cChristian.ChangeRoom on_mouse_click (MouseButton button)  ???.

Anyway, here's how I would code it:

First create the inventory item's look function (by clicking the events button) and add the code to change room.
Code: ags

function iClue1_Look()
{
	Display("You feel a weird sensation...");
	player.ChangeRoom(11); // assuming 11 is the room you wish to change to
}


On the rooms script, you now add after fade in (remember to link it on the events).

Code: ags

function room_AfterFadeIn()
{
         clue1Overlay = Overlay.CreateTextual (107, 114, 200, eFontNormal, 32784, "Blah, blah, blah.");
         Wait (200);
         DisplayAtY (115, "Click to continue.");
         player.ChangeRoom(player.PreviousRoom); // This should return you back to the previous room. :)
}


Note that I'm assuming that your code is correct.

PS - Matti beat me to the answer.  (laugh)
There are those who believe that life here began out there...

Khris

The on_event function doesn't work like that at all; thinking in events when you're used to procedural programming can be hell to wrap your head around, especially if you don't know when AGS does what.

The good thing is that you won't be needing it for this at all.

To assign look-at code to an inventory item, you select the item in the editor, navigate to its event pane (thunderbolt icon), then add the "Looks at inventory" event. This will add and link the function, and take you to the global script. In that function, send the player to the other room.
Regarding coordinates and returning, see Matti's post.

Zephyr

 ;-D

Thank you all for your (simply put) input.  I was reading all kinds of information from the tutorials, manual and also from (what I thought sounded like) problems similar to mine and I think I just got confused with it all and ended up overcomplicating the whole thing!  I will definitely rewrite and simplify.

Matti, you're quite right - I only created the Room 11 thing because I couldn't seem to code the Clue details to appear when looking at it within the inventory!  I would much prefer to do it that way, if I can cobble something together. 

Thank you all so much for your help.

- Zephyr
:-D
<3 Zephyr <3

SMF spam blocked by CleanTalk