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 :-\ :'(
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 )
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.
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 :(
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?
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.
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.
I didn;t use his script, as there isn't even a character in the room. It is a title page.
Whoops, I read something wrong. Sorry, I currently have the flu and am not thinking straight. :P Carry on.
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.
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 ???
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
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.
if (IsKeyPressed(13)==1) NewRoom(2);
Thats the code i got in there. doesn't work.
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.
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?
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
#sectionstart roomstart
function start()
{
if (IsKeyPressed(13)==1) NewRoom(2);
}
}
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. ;)
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...