Hello, I am new to these forums aswell as to adventure game studio. I have been working through the begginers tutorials and I have come across a problem that I cant seem to find the answer to. It seems that I cant put an "if" statement in dialog script, which i want because i want to have a dialog option hidden until the character has a certain inventory item, in my case it the item is inventury item #3. I put this in the dialog:
#
// dialog script file
@S // dialog startup entry point
if (player.inv[3]==1){
option-on 1
}
return
@1 // option 1
VENDOR: "Hmm lemme see that, ok sure you can have a hotdog but you have to give me the poster"
stop
@2 // option 2
VENDOR: "Have a nice day."
stop
the only problem is that if statements do not work in dialog script, so i can not run the game with this is. So how do you make it check for an inventory item and then show a dialog option if the item is present?
Sorry about the script, I couldnt figure out how to make it appear as script, i clicked on additional options and it said the shortcut was the # key, but that didnt work, and i cant find how or if you can edit the original post so i had to repost.
To make it appear as script, use can use the [ code ] or the [ pre ] (minus the spaces) tags.
Anyway, onto the problem... try this (changes in red):
// dialog script file
@S // dialog startup entry point
if (character[EGO].inv[3]==1) {
option-on 1
}
return
@1 // option 1
VENDOR: "Hmm lemme see that, ok sure you can have a hotdog but you have to give me the poster"
stop
@2 // option 2
VENDOR: "Have a nice day."
stop
Os, "player" is an alias for "character[EGO]".
As you said, you can't use if-statements in dialog scripts directly, so you have to use run-script:
// dialog script file
@S // dialog startup entry point
run-script 77
return
@1 // option 1
VENDOR: "Hmm lemme see that, ok sure you can have a hotdog but you have to give me the poster"
stop
@2 // option 2
VENDOR: "Have a nice day."
stop
Global script
function dialog_request(int parameter) {
if (parameter == 77) { // run-script 77 used
if (player.inv[3]) // if player has (1 or more of) inventory item 3
SetDialogOption(2, 1, 1); // option-on 1 in dialog 2
}
else
if (parameter == 44) { // run-script 44 used
// do other stuff
}
// and so on
}
Blah forgot to logon so now this is second time typing this.
I did exactly what strazer said to do in the dialog script, and in the global script i did this:
function dialog_request(int paramater){
if (parameter== 77) {
if (character[EGO].inv[2]){
SetDialogOption(1, 1, 1);Ã, Ã,Â
}
}
}
and the error i get when i try to run this is "nested functions not supported (you may have forgotten a closing brace)".Ã, I am fairly sure that I did not forget a closing brace, i placed the global script right before the last closing brace in the code.Ã, Any ideas how i can fix this so that i can have my dialog turn on if the character has a certain item?
/edit
heres a simple question: does putting if (character[EGO].inv[2]) vs if (character[EGO].inv[2]==1) make any difference? will the second one make it so that the character must only have 1 of the item for the script to work, and if the play has more then 1 it will not be executed?
You should keep the "==1" part just to be on the safe side.
As for the braces, I can't see anythng wrong.
function dialog_request(int paramater){
The braces are okay.
Quotei placed the global script right before the last closing brace in the code
dialog_script is a function in the global script, not the global script itself. The global script contains functions.
You have to put this function
after the last closing brace. You can not put a function into another function (nesting).
Quotewill the second one make it so that the character must only have 1 of the item for the script to work, and if the play has more then 1 it will not be executed?
Exactly.
I always use it like that so it still works if the player picked up an item twice or more (coins etc.).
problem is now solved, thanks a lot to all that helped me solve this. In case anyone else is wondering how to do this here is what i put in my scripts:
Dialog script
// dialog script file
@S // dialog startup entry point
run-script 77
return
@1 // option 1
VENDOR: "Hmm lemme see that, ok sure you can have a hotdog but you have to give me the poster"
stop
@2 // option 2
VENDOR: "Have a nice day."
stop
in global script
function dialog_request(int parameter){//for dialog scripts to add options and other things
if (parameter == 77){//if requested script is 77
if (character[EGO].inv[3]){//if main character has 1 or more of inv item number 3 (hot dog poster in this case)
SetDialogOption(1,1,1);
}
}
}