Dialogue scripting problem

Started by ty3194, Tue 09/03/2010 22:17:25

Previous topic - Next topic

ty3194

I have a problem when I'm  trying to make cJohn talk to cMike. When cMike asks cJohn to buy him some crack, I want to make the dialogue give you 2 options: A.) John: Yeah man.. whatever. & B.) John: Nah bro, I'm not getting any heat on me. When you choose A.) for the first time, I want cMike to give you $50 for buying it, and then have that option never appear again (so you can't keep talking to cMike and getting $50 each time), and if you choose B.) I want it to stop the dialogue and reset it next time you start up the dialogue. Here's what I have so far:

@S
Mike: Mike: Hey.. hey man.
John: John: Hey bro. You okay?
Mike: Mike: Yeah yeah yeah. Kind of..
John: John: You look fucked up.
Mike: Mike: (Laughing) Was.. coming down now. Think you can do me a favor? Here's $50; take it and go buy 3 rocks from Paul, the big dude with the gray jacket, I really need it. I would, but I don't think I would make it far.
return
@1
Mike: Mike: Thanks.

if (vMike == 0)
  Display("Mike reaches into his pocket and retrieves $50.");
  player.InventoryQuantity[iMoney.ID] += 50;
  UpdateInventory();
Mike: Mike: Keep the change.
  if (vMike == 1);
    Display("Did you get the rocks?")
   
  if (vMike < 1);
    vMike += 1;
   
stop
@2
Mike: Mike: Damnit man. Alright.. I'll just hit up one of my friends, have them do it.
stop


But it says

Dialog 0(11): Unknown command: if (vmike == 0). The command may require parameters which you have not supplied.
Dialog 0(15): Error (line 15): PE04: parse error at ';'

line 15 is

  if (vMike == 1);



PS: In case you were wondering, my dialogue I have it so it says the person's name in front of their dialogue I.E:

Mike: Mike: Hey.. hey man.

LRH

I believe what you're looking for is 'option-off X' where X is the number of the option.

Matti

1. You need a space before if (vMike == 0).

2. The semicolon after if (vMike == 1) and if (vMike < 1) doesn't make sense.

3. You have do add some brackets. This:

Code: ags

if (vMike == 0)
  Display("Mike reaches into his pocket and retrieves $50.");
  player.InventoryQuantity[iMoney.ID] += 50;
  UpdateInventory();


Should look like this:

Code: ags

if (vMike == 0){
  Display("Mike reaches into his pocket and retrieves $50.");
  player.InventoryQuantity[iMoney.ID] += 50;
  UpdateInventory();
}

ty3194

I now have:


@S
Mike: Mike: Hey.. hey man.
John: John: Hey bro. You okay?
Mike: Mike: Yeah yeah yeah. Kind of..
John: John: You look fucked up.
Mike: Mike: (Laughing) Was.. coming down now. Think you can do me a favor? Here's $50; take it and go buy 3 rocks from Paul, the big dude with the gray jacket, I really need it. I would, but I don't think I would make it far.
return
@1
Mike: Mike: Thanks.

if (vMike == 0)
{
  Display("Mike reaches into his pocket and retrieves $50.");
  player.InventoryQuantity[iMoney.ID] += 50;
  UpdateInventory();
}
Mike: Mike: Keep the change.
  if (vMike == 1);
    Display("Did you get the rocks?")
   
  if (vMike < 1);
    vMike += 1;
stop
@2
Mike: Mike: Damnit man. Alright.. I'll just hit up one of my friends, have them do it.
stop



But now I get these errors:

Dialog 0(11): Unknown command: if (vmike == 0). The command may require parameters which you have not supplied.
Dialog 0(12): Unknown command: {. The command may require parameters which you have not supplied.
Dialog 0(16): Unknown command: }. The command may require parameters which you have not supplied.
Dialog 0(15): Error (line 15): PE04: parse error at ';'


I basically want to make it like world of warcraft quests.. if you dont accept it at first, you can go back and accept it anytime. if you do accept it then it gives you a message the next time you go to talk to them if you havn't got the quest item/ objective complete (IE: Did you get the rocks?). And i'm going to make it so when you use the crack inventory item on him, it gives it to him and he says "thanks man." or somethng of that sort, and you get +score, which is going to be like WoW experience.

Khris

#4
Like Mr. Matti said: You need to put a blank space in front of code lines.

If the very first character in a line is a " ", AGS interprets the line as script line, otherwise as regular dialog script line, i.e. only the relatively few dialog commands can be used in those (e.g return, stop, etc.).

Code: ags
@S
Mike: Mike: Hey.. hey man.
John: John: Hey bro. You okay?
Mike: Mike: Yeah yeah yeah. Kind of..
John: John: You look fucked up.
Mike: Mike: (Laughing) Was.. coming down now. Think you can do me a favor?   [...] REMOVED REST OF LINE!
return

@1
Mike: Mike: Thanks.
 if (vMike == 0) {
   Display("Mike reaches into his pocket and retrieves $50.");
   player.InventoryQuantity[iMoney.ID] += 50;
   UpdateInventory();
 }
Mike: Mike: Keep the change.
 if (vMike == 1)
   Display("Did you get the rocks?")
 if (vMike < 1)
   vMike += 1;
stop

@2
Mike: Mike: Damnit man. Alright.. I'll just hit up one of my friends, have them do it.
stop


Look, no semicolon after the if-condition.

If you want to run one single command depending on whether a condition is true:
  if (condition) command;

Multiple commands need to be grouped together using {}s:
  if (condition) {
    command1;
    command2;
    command3;
  }

ty3194

#5
Okay so now it looks like this:



@1

Mike: Mike: Thanks.
 {
   if (vMike == 0)
   {
     Display("Mike reaches into his pocket and retrieves $50.");
     player.InventoryQuantity[iMoney.ID] += 50;
     UpdateInventory();
   
Mike: Mike: Keep the change.
   }
   if (vMike == 1);
   {
     Display("Did you get the rocks?")
   }
   if (vMike < 1);
   {
     vMike += 1;
   }
 }

stop




and I get this error for line 21:



Dialog 0(21): Error (line 21): PE04: parse error at ';'



line 21 is this:

    if (vMike == 1);

Matti

You still don't need a semicolon after if-statements...

Khris


Danman

#8
It would be easier  ty3194 if you put the code in a bracket like
Code: ags
 

[Code ] Whatever [ /Code] but without spaces.



And I thought Semi colon's in a If Statement would bring an error.



ty3194

#9
This post keeps messing up when I modify it.. keeps adding a code thing to the front.. have to make another post sorry

ty3194

Thanks.. I didn't know how people did that. It's almost completely fixed now (I removed the ; from the end of the line with an error and it worked this time. when I did that last time it said it "expected ;" but whatever), but after executing this:


Code: ags

if (vMike == 0)
    {
      Display("Mike reaches into his pocket and retrieves $50.");
      player.InventoryQuantity[iMoney.ID] += 50;
      UpdateInventory();
    }



it immediately executes this:


Code: ags

if (vMike < 1)
    {
      vMike += 1;
    }
      if (vMike == 1)
    {
      Display("Did you get the rocks?");
    }  



is there anyway to make it not execute immediatly?

this is the full code just in case you need it:



Code: ags

@1
Mike: Mike: Thanks. You can keep the change.
  {
    if (vMike == 0)
    {
      Display("Mike reaches into his pocket and retrieves $50.");
      player.InventoryQuantity[iMoney.ID] += 50;
      UpdateInventory();
    }
      if (vMike < 1)
    {
      vMike += 1;
    }
      if (vMike == 1)
    {
      Display("Did you get the rocks?");
    } 
      if (player.HasInventory(iCrack))
    {
      vMike += 1;
    }
      if (vMike == 2)
    {
Mike: Mike: You got the rocks? Nice.. hand them here chief, I'm fiendin'
    GiveScore(50);
    Display("Mission complete! You recieve 50 experience.");
    } 
  }
stop

@2
goto-dialog dMike2


CShelton

The reason your code immediately executes the next step in the dialog is because you're asking it to do this:

Assuming vMike is 0 when you start.

Is vMike 0?
Yes.
Add +1 to vMike.

and the very next line is:

Is vMike 1?

the answer is going to be yes again, because you just made vMike +1.

What you need to do is use ELSE IF's to control the flow of this script.

Code: ags

If (vMike == 0)
{
  vMike += 1;
}
else if (vMike == 1)
{
  vMike += 1;
}


When you use IF's and ELSE IF's in this way, your code will only execute the first true condition that comes along. So if vMike is 0, the ELSE IF line wouldn't even happen until the next time around. You can even do an ELSE statement at the end of a chunk of code that basically means "if none of that other stuff executed, do this as a last resort"

Code: ags

if (vMikeSmokedRocks == 1)
{
  Display ("vMike has experimented with crack.");
}
else if (vMikeSmokedRocks == 2)
{
  Display ("vMike is an occassional user of crack.");
}
else if (vMikeSmokedRocks > 2)
{
  Display ("vMike is a crack head .");
}
else
{
  Display ("vMike has never smoked crack.");
}


When you execute that last code snippet, only one of those Display lines would pop up. If vMike had smoked 2 rocks, it would display the line about him being an occasionally user, then it would move on past the rest of the code snippet.





SMF spam blocked by CleanTalk