I'm trying to make a yes/no prompt when you try to pick up and item (and will also use it for pivotal moments in my game).
Here's the script:
function hotspot1_a() {
// script for hotspot1: Interact hotspot
if (character[GetPlayerCharacter()].inv[1]>0){
}
else {
SetButtonPic(4,2,1,3);
SetLabelText(4,3,"Will you take your car keys?");
*GUIon(4);
if (interface_click (4,0)){
AddInventory(1);
GUIoff (4);
DisplayMessage("You got your car keys.");
}
if (character[GetPlayerCharacter()].inv[2]>0{
}
else {
SetButtonPic(4,2,1,2);
SetLabelText(4,3,"Will you take your lighter?");
GUIon(4);
if (interface_click (4,0)){
AddInventory(2);
GUIoff (4);
DisplayMessage("You got your lighter.");
}
if (character[GetPlayerCharacter()].inv[1]==1) && (character[GetPlayerCharacter()].inv[1]==1){
DisplayMessage ("It doesn't look like there's anything else I need in my car.");
}
When I run test the game, I get this error message:
Error (line 72) undefined token 'GUIon'
What does it mean "undefined"? Does it not say "GUIon (4)"?
If I'm mistaken, what does "undefined token" mean?
What did I do wrong in this script?
Also, just to save myself the hassle... did I do this right?
SetLabelText(4,3,"Will you take your lighter?");
Thanks in advance.
~Sully
It's case-sensitive, it should be GUI
On(4);
Similarly, it's GUI
Off.
QuoteSetLabelText(4,3,"Will you take your lighter?");
If the GUI is 4 and the object is 3, then yes, nothing I can see wrong with it.
Alright... I've been tinkering with this all night...
I modified the script to this:
if (character[GetPlayerCharacter()].inv[1]>0){
}
else {
SetButtonPic(4,2,1,3);
SetLabelText(4,3,"Will you take your car keys?");
GUIOn(4);
*(interface_click (4,0)){
AddInventory(1);
GUIOff (4);
DisplayMessage("You got your car keys.");
}
if (interface_click (4,1)){
GUIOff (4);
}
if (character[GetPlayerCharacter()].inv[2]>0{
}
else {
SetButtonPic(4,2,1,2);
SetLabelText(4,3,"Will you take your lighter?");
GUIOn(4);
if (interface_click (4,0)){
AddInventory(2);
GUIOff (4);
DisplayMessage("You got your lighter.");
}
if (interface_click (4,1)){
GUIOff (4);
}
}
if (character[GetPlayerCharacter()].inv[1]==1) && (character [GetPlayerCharacter()].inv[1]==1){
DisplayMessage ("It doesn't look like there's anything else I need in my car.");
}
I get this message:
There was an error compiling your script. The problem was:
In: 'Main Script'
Error (line 73): undefinded symbol 'interface_click'
Which reads by the little *:
*(interface_click (4,0)){
What I'm basically trying to do is make a Yes/No prompt for picking up items. The above script is in a room script, and as far as I know, it should work (but that's just me).
I realized I should be putting this into the global script, under the interface_click function, but I don't know any way I can manipulate this script from a room script if I did that (bah, I can't seem to put what I'm thinking into words correctly...)
Does anyone know what I'm talking about or how I can make this script work?
I know that this is something that I don't really NEED in my game, but the whole "YES/NO" prompt will be useful for later on when I add a branching effect to my game.
BTW: Strazer, has anyone ever told you that your avatar looks a lot like Bruce Campbell? (Ash from the Evil Dead)
Try putting
import function interface_click(int a, int b);
into the global header.
Something else may go wrong at this point - I'm not sure it's a good idea to be calling interface_click from another script - but it's worth a try.
[EDIT] I just reread what you're trying to do, and I'm waaaaay off.
Try something like this:
In Global header:
import int yesNoButton;
import int waitingForYesNo;
import int yesNoItem;
In Global script:
int yesNoButton = 0;
int waitingForYesNo = 0;
int yesNoItem = 0;
In repeatedly_execute:
if (waitingForYesNo > 0)
{
__if (yesNoButton == 1)
__{
____AddInventory(yesNoItem);
____DisplaySpeech("Got it.");
__}
__waitingForYesNo = 0;
}
In interface_click:
if (interface == 4)
{
__yesNoButton = button;
__GUIOff(4);
}
In room script:
DisplaySpeech(EGO, "Should I take the lighter?"); // EDIT - fixed
GUIOn(4);
waitingForYesNo = 1;
yesNoItem = 2;
If you want to ask if they want to take another item immediately afterwards it gets more complicated.
It might be better to display a GUI that has the appropriate objects in it and the player can just click to pick them up. Like a close up window.
Hmmm if you're doing this in a room script, you cant refer to functions declared in global script directly (functions in global script are by default NOT global to room scripts), so if you really need to do that, you have to put:
import interface_click(int, int);
on top of that room's script.
BUT I'm not quite sure what you really want with these codes, as normally the interface_click() function isn't designed to return a value unless it's scripted to return one.
(I haven't read everything in this thead, just the problem and the first solved points)
Make a GUI as the prompt, and for it's no-button set the interface_click function to just close the GUI, and the yes-button to set a globalint to a value, and in the room repeadetly execute check if this globalint is set to that value, do the pickup sequence, and set the globalint to something else, so the script isn't called repeadetly...
----- EDIT -----
Oops!sorry, I really didn't see Steve's code... :-[
Quote from: TK on Thu 12/02/2004 19:34:29
(I haven't read everything in this thead, just the problem and the first solved points)
So you wouldn't have seen that the code in my post does exactly what you said :)
I tried what you said, I put everything where you said to put it, Stevie.
Then when I tested the game, I got this error message:
Error (line 67): Type mismatch: String with non-string.
This is what line 67 says:
DisplaySpeech("Should I take the lighter?");
I have no clue what it's talking about, The whole line looks fine to me...
I don't know... maybe this whole "will you take the item?" feature is getting to be too much work (and you're the one doing most of my work for me, which isn't what I intended in the first place). I'm thinking about junking it and just using the Yes/No prompt for pivotal moments in the game (or not at all)... it's taking up a lot of production time I could be using to figure out more important things for my game (like AI).
Maybe I should suggest that CJ put a feature like this into the next AGS... a customizable yes/no prompt (kind of like the message windows...)
EDIT: D'OH! Sorry, Gilbot... (why do little things like that always slip my mind?...)
Because DisplaySpeech() takes TWO parameters:
DisplaySpeech(EGO, "blah bla bla");
Oops, I guess I should have tested that :)
I'll edit the code up there now.
Sully, I respect your attitude about wanting to do your own work! Don't know where you got "Stevie" from though... mum? dad? Is that you?
Steve
Make your YESNO-GUI popup modal.
--- script header ---
import function ask_user (int item, int object);
--- global script ---
// name the GUI elements
#define YESNO_LABEL 0
#define YESNO_BUTTON_YES 1
#define YESNO_BUTTON_NO 2
int yesno_item = -1;
int yesno_object = -1;
function ask_user (int item, int object)
{
yesno_item = item;
yesno_object = object;
string s;
GetInvName (yesno_item, s);
StrFormat (s, "Will you take your %s?", s);
SetLabelText (YESNO, YESNO_LABEL, s);
GUIOn (YESNO);
}
function interface_click(int interface, int button) {
... other interface stuff ...
else if (interface == YESNO)
{
GUIOff (YESNO);
if (button == YESNO_BUTTON_YES)
{
ObjectOff (yesno_object);
AddInventory (yesno_item);
string s;
GetInvName (yesno_item, s);
DisplaySpeech (EGO, "You got your %s.", s);
}
yesno_item = -1;
yesno_object = -1;
}
}
In the interaction of the object you just put:
ask_user (INV_ITEM, OBJECT);
with the correct numbers.
The user will be asked, then the object is switched off and the item is added to the inventory.
a-v-o, you are brilliant!
*Sully lays a big, fat, sloppy man kiss on a-v-o's cheek.
It works great! There are a few minor bugs and alterations that I can take care of, but other wise you've done well.
Here is a pic of what I was trying to accomplish;
(http://volcano.photobucket.com/albums/v11/bodyart/Screenshots/yesno.png)
I would have never been able to do this one on my own, as I'm not too familiar with making my own functions. I knew all along that C++ allows you to make your own functions, and AGS code is an emulation of C++ (if I"m not mistaken), but like I said, I'm not too familiar with the process of it. I haven't found anything in the manual about making your own functions.
I suppose, I should start taking down names, so that everybody gets the due credit when I'm done with this game. ;) Whaddaya think?
your GUI looks much nicer than my test GUI.
I saw in your script that you use a picture, but I thought you will find out how to place it. And you got it! ;D
Ah yes, very Resident Evil!
Nice keys too.