I have hit a dead end in coding my Map Screen in-game. I want to be able to bring up the Map Screen when the M key is pressed. But I keep getting error messages when I try and run the game. Here's what the code currently looks like;
function MapScreen;
if ((keycode == eKeyM)
{
cJack.ChangeRoom(1)
}
Would I also need to move said script away from the Global Script or is it ok where it is?
Finally, can somebody please demonstrate a way of stopping the script from working in the Map Screen itself?
You not specifying what errors you are getting, but I can see by what your code, that you have one ( too many... or a ) too less... also you missing a ; at the end of the changeroom line. and you also seem to be missing the {} that open and close the function...
Hope this helps.
function MapScreen;
{
if (keycode == eKeyM)
{
cJack.ChangeRoom(1);
}
}
As getting the script to stop am not sure what you mean?
I probably would suggest that you do a GUI for the map, if it's just an image to be displayed, and not an interactive room where you can move the player and have stuff happen.
This is still wrong; apart from the superfluous semi-colon, this function is never called.
There's no need for a custom function here; all you need to do is find the on_key_press function in GlobalScript.asc; it already contains code for several buttons.
Just add this to the end, before the function's final closing brace: }
if (keycode == eKeyM) {
if (player.Room != 1) player.ChangeRoom(1);
// uncomment the following to make M also go back
// else player.ChangeRoom(player.PreviousRoom);
}
Edit: fixed error in code
Thanks. I've added Khris' code and I get this error message.
GlobalScript.asc(213): Error (line 213): static non-property access: internal error
Hopefully it's just a silly mistake, but hey.
Also, would I be able to have the Tab button as a second Map key, so if you were playing on a laptop, you'd use the Tab key instead of the M key?
I had "eKeyCode" instead of "keycode".
To add a second key, just use
if (keycode == eKeyM || keycode == eKeyTab)
The code is adapted. Another issue has arisen with a code i haven't touched.
GlobalScript.asc(221): Error (line 221): Nested functions not supported (you may have forgotten a closing brace)
Here's what the code looks like
[code/ags]
if (keycode == eKeyM || keycode == eKeyTab) {
if (player.Room != 1) player.ChangeRoom(1);
// uncomment the following to make M also go back
// else player.ChangeRoom(player.PreviousRoom);
}
function on_mouse_click(MouseButton button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (IsGamePaused() == 1) {
// Game is paused, so do nothing (ie. don't allow mouse click)
[code/ags]
Also, how do I make it so that, for example, if the player walks onto the palm tree object on the map, it takes him to the desert. Does that make any sense?
EDIT: I changed 'keycode' to 'eKeyCode'
Quote
GlobalScript.asc(221): Error (line 221): Nested functions not supported (you may have forgotten a closing brace)
function on_mouse_click(MouseButton button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (IsGamePaused() == 1) {
// Game is paused, so do nothing (ie. don't allow mouse click)
}
}
alphadalekben, you probably have pasted my code in the wrong place, which is why I specifically told you where to put it.
Your script is supposed to look like this:
function on_key_press(eKeyCode keycode)
{ // <- function's opening brace
// lots of existing code here, indented
// add my code here
} // <- function's closing brace
The error you get typically occurs when AGS encounters the "function" keyword but the previous function has not been closed yet. My guess is you accidentally removed on_key_press's closing brace when pasting my code snippet.
As for a character's walking on something triggering an event: draw a region on the background, then use the region's "player walks onto" event.
To post code, use: [code=ags] ... [/code]
All fixed now thanks. :grin: By the way, Khris, what should the 'Player walks onto' event look like if it is set to go to Room 2 (both in the bottom right Events window and in the Global or Room Script (depending on what's better to use for this)?
Hopefully I make sense there.
You add an event just like described in the tutorial:
-click the "player walks onto" cell, and you should get a [...] button in the empty cell next to it.
-click that button and AGS will create the function in the appropriate place (in this case: the room script), naming and linking it
-add code inside the function
You should see a function added called region1_walksOnto or similar, and that very name should now appear in the cell next to the event name.
This is how you can link a function to a game event.
You did do the manual's tutorial, right...?
At what point does the tutorial tell you how to do regions? I can see hotspots but no reasons.
There IS a Region events (and functions and properties) topic section in the manual if you type Region Events in the manual search.
Apply Regions as you do with Hotspots.
Add events to them as how Khris said.
How do I get the region selector out of erasor mode and into a mode where i can select what region i want?
Exactly like with hotspots, there's a dropdown menu at the very top of the properties window where you can select the current region; region 0 acts as eraser.
I've put in the script to get the room to change to the desired location. Now, I just need the character to spawn on the walkable area.
These are the character's X and Y coordinates when he spawns when the game starts up (in the desert area).
StartX: 238
StartY: 224
player.ChangeRoom(2, 238, 224);
But this is not how these forums are supposed to be used. Your problems are extremely trivial, and the Beginner's Tech forum is not a replacement for trying to figure things out yourself using the tutorials and reference.
When I discovered AGS I spent weeks reading through the manual and forums. I'm not suggesting you absolutely have to do the same, but given that the answer to your problem is right in the manual entry for the command you are already using, maybe keeping the helpfile handy couldn't hurt.
Oh, right. Sorry for the misunderstanding. Thanks for all your help though :smiley:.
I'll be sure to keep your advice in mind.
Another minor issue here. I'm trying to get it so that the character spawns over the area icon (cactus for the desert etc (the ones I've drawn the regions over and I haven't set anything in the 'While standing on function' so nothing should trigger there). The issue is that I keep being sent back to the starting room.
Here is the code currently;
if (keycode == eKeyM) {
if (player.Room != 1) {
if (player.Room ==2) player.ChangeRoom(1, 160, 120);
if (player.Room ==3) player.ChangeRoom(1, 312, 173);
if (player.Room ==4) player.ChangeRoom(1, 275, 119);
}
else player.ChangeRoom(player.PreviousRoom);
I assume that the error occurs from the 'else' statement, but how do I go about fixing it?
While you don't have "while standing on" events, you are still moving the player there and thus triggering the "walks onto" events of the regions.
Here's what you can do to fix this:
Region *enteredRegion;
function room_Load()
{
Region *r = Region.GetAtRoomXY(player.x, player.y);
if (r.ID) { // if actual region, since no region returns region #0
enteredRegion = r;
r.Enabled = false;
}
}
function region15_WalksOnto()
{
enteredRegion.Enabled = true;
}
For this to work, use region 15 to flood fill the entire room around the regions that trigger the room changes. When the character first arrives, the region they end up on is disabled, then turned back on as soon as they step off it.
Naturally, you need to link the room's "before fadein" and region 15's "walks onto event" just like always, simply pasting this will, again, not work.
The order doesn't matter, as long as the Region declaration in line 1 is somewhere above the two functions. If you are already using room_Load(), just add my code at the start to the existing function.
Ah, cheers, Khris. I didn't think of that. Everything works well now, thank you very much. You know, with the amount you've done for me, I'll have to give you a credit in the finished game huh?
OK, I've another slight issue in another game I'm making. I want to make it so that, when the Space bar is pressed at certain times during a dialogue, it moves to a success dialogue option and carries on with the game, else it will restart the game at the previous room and you would have to restart the minigame.
Here is the error i'm getting:
Dialog 7(8): Error (line 8): Nested functions not supported (you may have forgotten a closing brace)
Here is my dialogue at the minute:
// Dialog script file
@S // Dialog startup entry point
return
@1
Darren: A moment later, I felt two hands grip tightly around my neck.
Darren: Agony took hold of my whole body as I struggled to break free.
Darren: I needed SPACE!
function on_key_press(eKeyCode keycode) {
if (eKeyCode == eKeySpace) {
option-off 1
option-on 2
}
else (player.ChangeRoom(4);
}
return
@2
Darren: My hands clutched what I assumed to be my attacker's arms and shoved back in terror.
Darren: But they still would not let me go free.
function on_key_press(eKeyCode keycode) {
if (eKeyCode == eKeySpace) {
option-off 2
option-on 3
}
else (player.ChangeRoom(4);
}
return
@3
Darren: So, I shoved again.
Darren: To no avail.
function on_key_press(eKeyCode keycode) {
if (eKeyCode == eKeySpace) {
option-off 3
option-on 4
}
else (player.ChangeRoom(4);
}
return
@4
Darren: Again.
Darren: No avail.
Darren: Then, as soon as it had started, the attack ceased.
stop
The issue being is that I know I need a bracket somewhere. I'm just not sure whereabouts in the script I need it.
You can't put functions into dialog script...
Dialog script is technically a one big function on its own. Or number of small functions... I forgot. But that's not important.
Your code also seems a bit messy...
as CW says, remove the functions line... in your elses line, you are opening a "(" but not closing it.
And I don't known if it's possible to put option code inside script code (I don't know AGS script that good to know this, sorry).
Scratch that, it is possible to use dialog code inside the script code... I've done that too. (http://www.adventuregamestudio.co.uk/forums/Smileys/AGS/smiley16_shy.png)
So, as CW said, remove the functions and check your brackets!
So would the key press still work if I remove the function?
Suggestions taken, but I'm still getting errors.
Here's my dialogue:
// Dialog script file
@S // Dialog startup entry point
return
@1
Darren: A moment later, I felt two hands grip tightly around my neck.
Darren: Agony took hold of my whole body as I struggled to break free.
Darren: I needed SPACE!
if (eKeyCode == eKeySpace) {
option-off 1
option-on 2
}
{
else (player.ChangeRoom(4);
}
return
@2
Darren: My hands clutched what I assumed to be my attacker's arms and shoved back in terror.
Darren: But they still would not let me go free.
if (eKeyCode == eKeySpace) {
option-off 2
option-on 3
}
{
else (player.ChangeRoom(4);
}
return
@3
Darren: So, I shoved again.
Darren: To no avail.
if (eKeyCode == eKeySpace) {
option-off 3
option-on 4
}
{
else (player.ChangeRoom(4);
}
return
@4
Darren: Again.
Darren: No avail.
Darren: Then, as soon as it had started, the attack ceased.
stop
Here's the error message:
Dialog 7(8): Error (line 8): static non-property access: internal error.
This is not the error you are getting, but I can't help you with that, cause I don'¨t know myself how to that, but I can help you with these lines (that will give error, once you solve your key press problem)
change these lines else (player.ChangeRoom(4); to
else
player.ChangeRoom(4);
Updated with Cassie's suggestion;
// Dialog script file
@S // Dialog startup entry point
return
@1
Darren: A moment later, I felt two hands grip tightly around my neck.
Darren: Agony took hold of my whole body as I struggled to break free.
Darren: I needed SPACE!
if (eKeyCode == eKeySpace) {
option-off 1
option-on 2
}
{
else
player.ChangeRoom(4);
}
return
@2
Darren: My hands clutched what I assumed to be my attacker's arms and shoved back in terror.
Darren: But they still would not let me go free.
if (eKeyCode == eKeySpace) {
option-off 2
option-on 3
}
{
else
player.ChangeRoom(4);
}
return
@3
Darren: So, I shoved again.
Darren: To no avail.
if (eKeyCode == eKeySpace) {
option-off 3
option-on 4
}
{
else
player.ChangeRoom(4);
}
return
@4
Darren: Again.
Darren: No avail.
Darren: Then, as soon as it had started, the attack ceased.
stop
I'll upload the fruits of my labour (when I mean labour, I mean over the last 24 hours) onto the 'Games In Production' Forum once I've sorted out this issue.
Err, guys, I see you have a serious miscomprehension of how the script works.
First of all,
if (eKeyCode == eKeySpace)
This does not makes a sense, because you are comparing the type (eKeyCode) with value (eKeySpace).
In the default "on_key_press" function you have "keycode" parameter that you use further, like
function on_key_press(eKeyCode keycode)
{
if (keycode == eKeySpace)
...
}
However here in dialog script there's no way you can get the pressed key code. When player presses a key, the "on_key_press" script function is called, and that must be located in the normal script, not dialog script.
You won't be able to "catch" key presses inside dialog script, at all.
You need to design your game in a different way. For example, you may need to stop dialog at this point, set up some variable (like "being in dialog"), then check this variable in the normal "on_key_press" and handle key presses for dialog there. Then start the second part of dialog.
Example:
function on_key_press(eKeyCode keycode)
{
if (IAmInDialog)
{
if (keycode == eKeySpace)
{
Dialog2.Start(); // start second dialog
}
}
... the rest of your "on_key_press" function
}
That said, I am not sure that you need to use a Dialog here at all. You can make character say things from normal script too with character.Say(...). (But this is a question of game design).
Cheers man. Now, one more question. Would I be able to call up dialogues (eg dEAttackD) with the player.Say function? So, to illustrate, it could be player.Say (dEAttackD) or player.Say (7).
EDIT: Scrap that, doesn't work. What on earth does this error message mean?:
Unexpected error: Cannot open file game28.dta for writing
EDIT #2: I've a terrible feeling the whole game's just corrupted.
Off the cuff,
Did the computer shut down, like as in an electric power cut off etc?
One thing we all learn in the end: Make a regular backup copy.
The file may well be corrupted.
Before you try this please wait for a confirmation....or your own risk choice, better to copy the whole game folder and put it somewhere else as a backup first before trying:
If ags will not load the game at all you could try, as a last result, taking the Game ags file out of the games folder and renaming the Game.agf file to just Game. Now try loading from the game.
Would someone please confirm this?
I have no idea, as the computer didn't shut down. It also said that one of the room files was missing. Oh well, I'm just reimporting and rescripting everything into a new game, just to make things easier. Hey, I should be able to get the demo done tomorrow and get it on the 'Games In Production' forum. Now, I just need to rework the PANIC! section in the demo.
Edit: I bet you're onto something with relocating the demo PANIC! section into the Global Script. Cheers for the suggestion.
Here's the 'Games In Production' topic, in case you're interested.
http://www.adventuregamestudio.co.uk/forums/index.php?topic=50788.0
Well, I've come up with a new solution to the issue. But, the game hangs when changing to the next room.
Here is the code for both dialogues;
Dialogue 1
// Dialog script file
@S // Dialog startup entry point
return
@1
Darren: So, I shoved again.
Darren: To no avail.
if (DarrenThrust ==1)
{
SetGlobalInt (1,0);
}
if (DarrenThrust ==0)
{
player.ChangeRoom (6);
}
else SetGlobalInt (1,1);
stop
Dialogue 2
// Dialog script file
@S // Dialog startup entry point
return
@1
Darren: Again.
Darren: No avail.
if (DarrenThrust ==1)
{
SetGlobalInt (1,0);
}
if (DarrenThrust ==0)
{
player.ChangeRoom (6);
}
else SetGlobalInt (1,1);
stop
I've a feeling it's something terribly simple AGAIN, but hey ho.
Yes, Try:
1st an if, 2nd and so on should then be else if, and the last one is else
you can't have if, if, if...else. Needs to be if, else if, else if...else. ;)
// Dialog script file
@S // Dialog startup entry point
return
@1
Darren: Again.
Darren: No avail.
if (DarrenThrust ==1)
{
SetGlobalInt (1,0);
}
else if (DarrenThrust ==0)
{
player.ChangeRoom (6);
}
else SetGlobalInt (1,1);
stop
Don't know if that's the only fail, but give it a try.
I have a strong suggestion not to use SetGlobalInt and GetGlobalInt, but use global variables instead (see Global Variables node in project tree). This way you will be able to address variables by their names, and not numbers (which may lead to lots of mistakes).
http://www.adventuregamestudio.co.uk/manual/ags19.htm#globalvariables
Set / GetGlobalInt are functions from older versions of AGS, and now considered deprecated (they exist only for compatibility with old projects).
Cheers for that, CW. Yet another bleeding issue now (yeah, I know). When I click on the first hand, the game acts as though I've clicked both hands, sending me into the next section of the game.
Here's the code:
Dialogue 1:
// Dialog script file
@S // Dialog startup entry point
return
@1
Darren: Again.
Darren: No avail.
if (DarrenThrust ==2)
{
DarrenThrust = 1;
}
if (DarrenThrust ==1)
{
DarrenThrust = 0;
}
if (DarrenThrust ==0)
{
player.ChangeRoom (6);
}
stop
The coding is the same for both dialogues.
Hey at least it works.
As Cassiebsg has already pointed you out two posts above (http://www.adventuregamestudio.co.uk/forums/index.php?topic=50722.msg636493721#msg636493721), you should use if / else if construction.
Let's look at your code:
if (DarrenThrust ==2)
{
DarrenThrust = 1;
}
if (DarrenThrust ==1)
{
DarrenThrust = 0;
}
if (DarrenThrust ==0)
{
player.ChangeRoom (6);
}
What you have here is three separate conditions.
What happens: if DarrenThrust was 2, it will go under first condition and become 1. But then, it will check against second condition, and since it is now 1, it will become 0. Then it will check against third condition, and since it is now 0, the player will change room.
What you should use: a if / else if construction:
if (DarrenThrust ==2)
{
DarrenThrust = 1;
}
else if (DarrenThrust ==1)
{
DarrenThrust = 0;
}
else if (DarrenThrust ==0)
{
player.ChangeRoom (6);
}
In this case only one of variants may be used at a time.
More information on if/else:
http://www.adventuregamestudio.co.uk/wiki/Scripting_tutorial_part_2#Doing_one_thing_or_another
Thank you very much.
And with that, the demo is now complete. I'll edit the post when it's uploaded.
EDIT: The demo is uploaded. Check the 58 thread in the 'Games In Production' forum to download it.