Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: 00jon00 on Sun 25/01/2004 04:24:24

Title: Interact with things/talk to people with key command
Post by: 00jon00 on Sun 25/01/2004 04:24:24
Ok, In the game I'm making you only use the mouse to do things in menus e.g. the save menu.  Im trying to make it so if you want to talk to someone or interact with something you walk up to it and press spacebar...I know spacebar ASCII code, but I don't know how to make the interaction deal work..Does anybody know how to do it?
Title: Re:Interact with things/talk to people with button
Post by: Ishmael on Sun 25/01/2004 13:10:49
Using either the  on_key_press or the repeadetly_execute function...

In key_press:

if (keycode==32) {
// the code here
}

in rep_ex:

if (IsKeyPressed(32)==1) {
// the code here
}

I guess...
Title: Re:Interact with things/talk to people with button
Post by: Bernie on Sun 25/01/2004 13:11:58
TK - I think he's using the keyboard to control the main character, and only the menu is mouse-driven, so he needs to somehow detect what's in front of the character to trigger an action when space is pressed.

I have very, uh, un-proper ways of achieving stuff so you might want to wait for a different suggestion. Anyway, here's mine:

You could use a seperate, invisible (max. transparency) character which you set to be in front of your character (using character[YAY].x and .y) that acts as a detector.
Make sure it's always in the same room as the main char.

You'd have to do make seperate positioning code for each of the 4 directions. Now you can test if the detector character is colliding with a different character.

Check AreCharObjColliding and AreCharactersColliding in the help for more info.

This is all theory only, but it should, in theory, work! :)
Title: Re:Interact with things/talk to people with button
Post by: Pumaman on Sun 25/01/2004 13:15:48
Well, you could do something like this:

if (keycode == ' ') {
 if (character[EGO].loop == 0) ProcessClick(character[EGO].x, character[EGO].y + 5, MODE_USE);
 else if (character[EGO].loop == 1) ProcessClick(character[EGO].x + 10, character[EGO].y, MODE_USE);
 else if (character[EGO].loop == 2) ProcessClick(character[EGO].x - 10, character[EGO].y, MODE_USE);
 else ProcessClick(character[EGO].x, character[EGO].y - 10, MODE_USE);
}

That way, it will run the interaction of whatever is just in front of the player. ie. if they are facing down, it will run the interaction of whatever is below them.

The actual offsets (5 and 10) might need some adjustment to make it work as you want it to, and you'd also need the hotspots to be quite large to make sure that the player could activate them easily.
Title: Re:Interact with things/talk to people with button
Post by: 00jon00 on Sun 25/01/2004 19:09:41
Thanks guys...I'll try the stuff you said, and if it dosn't work then I'll re-post
Title: Re:Interact with things/talk to people with button
Post by: 00jon00 on Sun 25/01/2004 19:21:41
Ok, Im kinda confused about Bernhard's idea..I'm still learing...and when I tried Pumaman's i just got an error:
---------------------------
Compile Error
---------------------------
There was an error compiling your script. The problem was:

In: 'Main script'

Error (line 23): Nested functions not supported (you may have forgotten a closing brace)



Do you want to fix the script now? (Your room has not been saved).
---------------------------
Yes   No  
---------------------------
Title: Re:Interact with things/talk to people with button
Post by: 00jon00 on Sun 25/01/2004 19:34:37
Ok, i got pumaman's Idea to work..kind of...no matter what where you are and you press space bar, it goes through all the interactions for that room..Im lost...you don't even have to stand on the hotspot-or anywhere near it...It also does the interactions for menu buttons.
Title: Re:Interact with things/talk to people with button
Post by: Ytterbium on Sun 25/01/2004 23:09:55
I think it might work better if you did it Grim Fandango style.

Have regions or hotspots near objects where if the character stands in them, they will be using that object. For example, if my character is standing in region A, they are near object A. If they are in region B, they are near object B.

If a character is in the region or hotspot which determines the active object, make a little sprite circle around the object to indicate that's what is active. Then when the player presses the spacebar, trigger the interaction.

Title: Re:Interact with things/talk to people with button
Post by: 00jon00 on Mon 26/01/2004 00:58:37
Im confused...
Title: Re:Interact with things/talk to people with key command
Post by: Pumaman on Sat 31/01/2004 14:18:43
How much AGS scripting experience do you have? If you're quite new to it, I'd recommend leaving the interface for now as just the standard supplied sierra one. Carry on making the game and you'll get more used to how AGS works, then come back to the interface and you'll find it much easier to understand how to change it.
Title: Re:Interact with things/talk to people with key command
Post by: 00jon00 on Sun 01/02/2004 22:26:20
I've been using AGS for awhile now, and I now quite a bit of scripting...I just can't get THIS to work?
Title: Re:Interact with things/talk to people with key command
Post by: a-v-o on Mon 02/02/2004 23:25:58
I've put a demo here:
http://a-v-o.selfhost.de/ags/download/spacebar.zip

used stuff:
room1:
- object0: sprites 6 and 7; custom property "inv_item"
- region1 around object 0 with 2 interactions

look at "spacebar" lines in global header and script.