Judgement Day - Various AGS Queries.

Started by Magic, Sun 14/07/2013 20:41:42

Previous topic - Next topic

Magic

Quote from: Khris on Tue 16/07/2013 17:51:56
First of all: you need to work with the manual more.

If you're getting a parse error when using a command, look it up. In the manual entry for Display is a link to the string formatting section, which contains this at the very beginning:
QuoteThis means that you intersperse your text with special codes to insert a variable's value. These special codes begin with a percent sign, and then specify the variable type. The actual variables that you want to display are then listed afterwards.
Thus:
Code: ags
  Display("The date is %02d:%02d for the case of McCarthy vs. Hargreaves.", dt.Hour, dt.Minute);

(Nevermind for now that you're still using the hour and minute, not month and day.)
I'm gradually working my way the manual, but I did base it off what you told me in this thread, I assumed that would be enough.

QuoteRegarding your problem with the inventory item inside the dialog script:
As soon as you have typed the first three letters of any object or function or whatever, a window will pop up and suggest existing stuff from your game, like for instance inventory items.
I don't get how people do not use this, sorry. It's pretty much impossible to get the spelling of something wrong that way. The relevant entry is the script name, the one you entered in the inventory item's properties under Design/Name. The Appearance/Description one is the one the player is going to see. As an example: Name would be "iBlueCup" and Description would be "blue cup".
Yes, I've kept the inventory item name simple - in this instance I have 'C1Photo1' but I'm still getting the error. The spelling is not the issue here.

Quote from: monkey_05_06 on Wed 17/07/2013 04:20:48
Quote from: Khris on Tue 16/07/2013 17:51:56Also please ignore Sunny Penguin's reply since using dialog_request has been obsolete for years now.

Only since 2008, I mean...that was practically yesterday.
That actually was when I last used AGS. I actually have a stored version of it from back then in case I want to update my uni project... :D

Quote from: Pumaman on Wed 24/12/2008 14:02:32
As to the issue of calling "Dialog.SetOptionState", you could also use the dialog script command "option-on" but you have to remember that dialog script commands are not indented in dialog scripts, normal scripting commands are. This is a special case where indentation should be used for something other than separating blocks of code, but if you have conditionals or loops in a dialog script then normal indentation rules should still be applied.

And yes, Khris, I agree that a firm introduction to Artie Effim (best known by his initials, RTFM) is in order. Or maybe even, dare I say it... RTFHTRTFMM. := (Just don't take it too personally Magic, it's the same process I tell everyone to follow :P)
I'm still getting back to speed on AGS so please excuse me. And hey, my original project was an IT Technician sim, complete with a poster with "RTFM" on it in the game's IT department.

I've read through the last few posts several times but I'm still at a loss here. The inventory item is correctly referenced. The return dialog is using aforementioned return macro. What do I need to do?

Code: ags
@5
EGO: Do you believe your workmanship was of a high standard?
C1Hargreaves: Of course, Your Honour. I did what I said I'd do - I put in those kitchen units.
 if (EGO.HasInventory(C1Photo1)) {
    EGO.Say("You recall that you have photos of the kitchen following Hargreave's work and consider asking him about them.");
 dialog[4].SetOptionState(6, eOptionOn);
 return RUN_DIALOG_RETURN;
  }
return
- Magic

monkey0506

Quote from: Magic on Tue 16/07/2013 14:52:364. New: If Player has inventory during Dialog

If the player has an item in their inventory, I want to enable a new dialog option.

Code: ags
@5
EGO: Do you believe your workmanship was of a high standard?
C1Hargreaves: Of course, Your Honour. I did what I said I'd do - I put in those kitchen units.
 if (EGO.HasInventory(C1_Photo1)) {
    EGO.Say("You recall that you have photos of the kitchen following Hargreave's work and consider asking him about them.");
 option-on 6
 return RUN_DIALOG_RETURN;
  }
return


I've tinkered with this and followed it from the AGS help file but get:
Dialog 4(27): Error (line 27): Parse error in expr near '0.'

Any ideas?

I think myself and Khris got a bit caught up in our snarkiness and didn't catch the real issue here.

When you start a new game, by default the first character is assigned the script name cEgo. For any Character whose script name starts with c, AGS automatically (for legacy purposes) generates a macro with the remainder of the Character's name in all caps and the value of the Character's ID. So, for cEgo AGS will generate a macro named EGO with the value of 0 (zero, the first character's ID).

In dialog scripts you use either the macro-style name or the real script name:

Code: ags
// dialog script
@1
EGO: Hello // macro-style name
cEgo: World! // real script name
stop


In normal scripts (including indented dialog scripts, which are parsed as normal scripting commands) the macro is evaluated by the preprocessor and replaced with the Character's ID. So if you use the macro name in a normal script:

Code: ags
// GlobalScript.asc, inside some function
EGO.Say("blah blah blah");


You will get an error:

QuoteError (line 27): Parse error in expr near '0.'

This is because what you're really doing by using the macro name is this:

Code: ags
// GlobalScript.asc, inside some function
0.Say("blah blah blah");


AGS doesn't treat integer-literals as objects, so you obviously can't call a Say function on one.

In normal scripts you should always use the real script name, not the macro name:

Code: ags
// GlobalScript.asc, inside some function
cEgo.Say("blah blah blah");


By extension, this applies to any indented lines in a dialog script. So, finally, your dialog script should now look something like this:

Code: ags
@5
EGO: Do you believe your workmanship was of a high standard?
C1Hargreaves: Of course, Your Honour. I did what I said I'd do - I put in those kitchen units.
  if (cEgo.HasInventory(C1Photo1)) {
    cEgo.Say("You recall that you have photos of the kitchen following Hargreave's work and consider asking him about them.");
    dialog[4].SetOptionState(6, eOptionOn); // alternately undent and use "option-on 6", presuming this is dialog 4
    return RUN_DIALOG_RETURN;
  }
return


The defacto standard for script names of Characters in AGS is to prepend the name with a lower-case 'c'. From AGS 2.7 through 2.72 this was handled automatically. AGS 3.0 and onward have allowed you to specify the full script name of things, but it's still customary to have cCharactername vs just Charactername. To help prevent confusion though, I'd suggest avoiding the macro names altogether, even in dialog scripts, and just stick to using the script name.

On that note, though it's not required, some customary naming conventions for (global) things in AGS (entirely preferential, so find what works best for you):

AudioClips: aAudioclipname
Characters: cCharactername
Dialogs: dDialogname
Enumerated values: eEnumvaluename
GUIs: gGuiname
GUI Buttons: btnButtonname
GUI InvWindows: invInvwindowname
GUI Labels: lblLabelname
GUI ListBoxes: lstListboxname
GUI Sliders: sldSlidername
GUI TextBoxes: txtTextboxname
Hotspots: hHotspotname
InventoryItems: iInventoryitemname
Objects: oObjectname

Again, you don't have to name things this way, but it helps keep things somewhat organized, as well as helping identify what the thing is by its name. ;)

Khris

Dang, I was looking through the script for a constant with value 0, but completely missed the "EGO" part of EGO.HasInventory().

Magic:
Quote from: Magic on Wed 17/07/2013 21:10:34I'm gradually working my way the manual, but I did base it off what you told me in this thread, I assumed that would be enough.
But, you got a specific parse error when you changed the Display() content, right? So it obviously wasn't enough. You don't get to ask stuff like that while everybody else is referred to the manual, not even if you had coded AGS's game of the year in 2008. There is no excuse for not checking the manual first.

Magic

Quote from: monkey_05_06 on Wed 17/07/2013 21:41:07
Quote from: Magic on Tue 16/07/2013 14:52:364. New: If Player has inventory during Dialog

If the player has an item in their inventory, I want to enable a new dialog option.

Code: ags
@5
EGO: Do you believe your workmanship was of a high standard?
C1Hargreaves: Of course, Your Honour. I did what I said I'd do - I put in those kitchen units.
 if (EGO.HasInventory(C1_Photo1)) {
    EGO.Say("You recall that you have photos of the kitchen following Hargreave's work and consider asking him about them.");
 option-on 6
 return RUN_DIALOG_RETURN;
  }
return


I've tinkered with this and followed it from the AGS help file but get:
Dialog 4(27): Error (line 27): Parse error in expr near '0.'

Any ideas?

I think myself and Khris got a bit caught up in our snarkiness and didn't catch the real issue here.
Ah, of course. Got it. It's the same mistake as the lack of indentation earlier for certain commands in the dialog script. It works now, thanks a lot! :)

That concludes my main queries - I should be able to finish off the prototype. The only other part I can think of is a in some dialog where each of the 4 answers from the player leads to the same result so rather than copy and paste the same dialog into each I'll try to re-direct them. I'll try to work that out myself though. Probably a variable or such.
Quote from: Khris on Thu 18/07/2013 09:35:16
Dang, I was looking through the script for a constant with value 0, but completely missed the "EGO" part of EGO.HasInventory().

Magic:
Quote from: Magic on Wed 17/07/2013 21:10:34I'm gradually working my way the manual, but I did base it off what you told me in this thread, I assumed that would be enough.
But, you got a specific parse error when you changed the Display() content, right? So it obviously wasn't enough. You don't get to ask stuff like that while everybody else is referred to the manual, not even if you had coded AGS's game of the year in 2008. There is no excuse for not checking the manual first.
. . .
- Magic

Khris

Yay, I FUCKING LOVE PASSIVE AGGRESSIVENESS!

SMF spam blocked by CleanTalk