Help wanted to get the M key to bring up the Map Room

Started by alphadalekben, Tue 15/07/2014 17:44:08

Previous topic - Next topic

alphadalekben

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:

Code: ags

// 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.

Crimson Wizard

#21
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.

Cassiebsg

#22
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.
So, as CW said, remove the functions and check your brackets!
There are those who believe that life here began out there...

alphadalekben

So would the key press still work if I remove the function?

alphadalekben

Suggestions taken, but I'm still getting errors.

Here's my dialogue:

Code: ags

// 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.

Cassiebsg

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

Code: ags

  else 
       player.ChangeRoom(4);
There are those who believe that life here began out there...

alphadalekben

Updated with Cassie's suggestion;

Code: ags

// 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.

Crimson Wizard

#27
Err, guys, I see you have a serious miscomprehension of how the script works.

First of all,
Code: ags

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
Code: ags

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:
Code: ags

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).

alphadalekben

#28
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.

Slasher

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?



alphadalekben

#30
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.


alphadalekben

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
Code: ags

// 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
Code: ags

// 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.

Cassiebsg

#33
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. ;)

Code: ags

// 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.
There are those who believe that life here began out there...

Crimson Wizard

#34
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).

alphadalekben

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:
Code: ags

// 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.

Crimson Wizard

As Cassiebsg has already pointed you out two posts above, you should use if / else if construction.

Let's look at your code:
Code: ags

  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:

Code: ags

  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

alphadalekben

#37
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.

SMF spam blocked by CleanTalk