Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: TokyoBlade on Sun 06/03/2005 14:49:46

Title: Press a Key, goes to next room
Post by: TokyoBlade on Sun 06/03/2005 14:49:46
so, how do you do it? I've tried many different ways but none work, i want it so only in that one room you can press it and it goes to next room. It only works so far in Global Scripts, but that affects every room  :-\  :'(
Title: Re: Press a Key, goes to next room
Post by: .. on Sun 06/03/2005 15:07:05
In the on key press in the global script under whatever key it is you want.


if (character[EGO].room==X)
{NewRoom (int room_number) }

EGO = player name
x = room you want this script to work in

( I don't have AGS on my pc at the mo but i think that's right )
Title: Re: Press a Key, goes to next room
Post by: on Sun 06/03/2005 15:12:13
Alternatively, you can create a seperate on_key_press function in the room script ot handle anything you only want to happen in that room. You might need to use ClaimEvent (), if the keycode is also used in the global script - look it up for details.
Title: Re: Press a Key, goes to next room
Post by: TokyoBlade on Sun 06/03/2005 15:24:46
Thanks for the replies. And i think i missed something out in my first post. It is a title page, you press RETURN then it starts the game.

And LazyAshen, i tried that 'on_key_press' in room script thing, didn't seem to work :(
Title: Re: Press a Key, goes to next room
Post by: Ashen on Sun 06/03/2005 15:40:18
I don't think whcih room you're in and where you want to go particularly matters, especially if you can't get it working at all. Scuthbert's suggestion should work, though.

Quote from: TokyoBlade on Sun 06/03/2005 15:24:46
i tried that 'on_key_press' in room script thing, didn't seem to work :(
Out of curiousity, what script did you have, and where did you put it? Did it return an error, or just not do anything?
Title: Re: Press a Key, goes to next room
Post by: TokyoBlade on Sun 06/03/2005 15:42:39
Quote
Out of curiousity, what script did you have, and where did you put it? Did it return an error, or just not do anything?

I've deleted the script, but if it really matters i'll try and remember what i put. And there was no error, i tested game and it loaded up fine, but script did nothing.
Title: Re: Press a Key, goes to next room
Post by: TerranRich on Sun 06/03/2005 18:42:57
Always remember: You must first understand a script in order to use it. Don't cut copy & paste, it doesn't always work out that way. Can you say that you fullly understand how to use Scuthbert's script, where to insert your own numbers instead of the labels he provided, and how the global script works? If not, read the manual and try it again.
Title: Re: Press a Key, goes to next room
Post by: TokyoBlade on Sun 06/03/2005 21:22:13
I didn;t use his script, as there isn't even a character in the room. It is a title page.
Title: Re: Press a Key, goes to next room
Post by: TerranRich on Sun 06/03/2005 23:50:36
Whoops, I read something wrong. Sorry, I currently have the flu and am not thinking straight. :P Carry on.
Title: Re: Press a Key, goes to next room
Post by: on Mon 07/03/2005 19:32:19
If I understand your problem correctly, you have a room for the intro, labeled as such, which the player isn't in, and when the title is displayed, you want to wait for the user to press enter, right?  I think,

// in room script for intro
// stuff
// last line:
while (IsKeyPressed(13) == 0) Wait(1);
}


will work.  I'm not 100% sure, but I think something like that would work.  Or maybe just:

while (IsKeyPressed(13) == 0) {};

But you may want verification on this.
Title: Re: Press a Key, goes to next room
Post by: TokyoBlade on Mon 07/03/2005 21:55:25
hmmm... Maybe I have a different version to everyone else? I have tried all your suggestions, but they dont work :( I save the room, test game and nothing happens.

Either that or I am missing something REALLY obvious  ???
Title: Re: Press a Key, goes to next room
Post by: Bad Voo-doo man on Tue 08/03/2005 00:02:58
Can't you just set a room interaction for repeadedly execute, then have
if (IsKeyPressed(##)==1) {
Ã,  Ã,  Ã,  Ã,  Ã,  NewRoomEx(#, #, #);
}


But that would only work if you checked off enforce object based script, and filled in the #s with the appropriate number
Title: Re: Press a Key, goes to next room
Post by: Scorpiorus on Tue 08/03/2005 18:10:00
TokyoBlade:
Anyway, either of what has been suggested should really work. If it still doesn't, posting your room script could help us to find out what's possibly wrong.
Title: Re: Press a Key, goes to next room
Post by: TokyoBlade on Tue 08/03/2005 21:19:45
if (IsKeyPressed(13)==1) NewRoom(2); 

Thats the code i got in there. doesn't work.
Title: Re: Press a Key, goes to next room
Post by: Scorpiorus on Tue 08/03/2005 21:25:30
What I meant is posting the whole script of the room where the player is supposed to press enter.

EDIT:
There is a {} button in the room editor that leads to the script.
Title: Re: Press a Key, goes to next room
Post by: Bad Voo-doo man on Tue 08/03/2005 22:31:05
Quote from: TokyoBlade on Tue 08/03/2005 21:19:45
if (IsKeyPressed(13)==1) NewRoom(2);Ã, 

Thats the code i got in there. doesn't work.

Is your > if (IsKeyPreesed(13)==1) {
                        NewRoom(2);
               }

under a repeatedly execute interaction?
Title: Re: Press a Key, goes to next room
Post by: MillsJROSS on Wed 09/03/2005 05:25:56
Just wanted to mention, that whether or not your main character is visible in the room, he/she/it is still in that room. Or it was so in the version I have.

-MillsJROSS
Title: Re: Press a Key, goes to next room
Post by: TokyoBlade on Wed 09/03/2005 16:21:43
#sectionstart roomstart
function start()
{
if (IsKeyPressed(13)==1) NewRoom(2); 

}
Title: Re: Press a Key, goes to next room
Post by: Scorpiorus on Wed 09/03/2005 16:54:18
Ok, here is the problem:
You have "if (IsKeyPressed(13)==1) NewRoom(2);" within the "start()" function which means that in order for the code to work the "start()" function has to be invoked somehow. But the problem is that internally AGS doesn't invoke that function because it doesn't know when it should do that.

What you need to do is use a special function instead.
To create such function open the room interaction editor, choose Repeatedly execute interaction, next choose the Run Script action and press the Edit script... button. You'll see somethink like:
Ã,  // script for room: Repeatedly execute


Just add your code in there:
Ã,  // script for room: Repeatedly execute

if (IsKeyPressed(13)==1) NewRoom(2);


That should do the trick!


By the way, take a look at the whole script again, afterwards. You'll find there is new function was automatically added by AGS which looks like:

#sectionstart room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_X() {
Ã,  // script for room: Repeatedly execute

if (IsKeyPressed(13)==1) NewRoom(2);

}
#sectionend room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE

where X stands for some letter (a or b or c etc.)

This room_X function will repeatedly be invoked by AGS.

But bear in mind, you must always add such functions only via the interaction editor. Otherwise they won't automatically be invoked by AGS, since it won't know which interaction a certain function must be run on.

Let us know how things turn out. ;)
Title: Re: Press a Key, goes to next room
Post by: TokyoBlade on Wed 09/03/2005 20:29:53
Woah, thanks for that Scorpiorus  :)

I didn't know you needed to go into interactions...

My script now looks like this:

#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
  // script for room: Repeatedly execute
 
if (IsKeyPressed(13)==1) NewRoom(2);
}
#sectionend room_a  // DO NOT EDIT OR REMOVE THIS LINE


BUT, when I test the game, the button still doesn't work  :o

Mysterious? Seems to be...