Interact with things/talk to people with key command

Started by 00jon00, Sun 25/01/2004 04:24:24

Previous topic - Next topic

00jon00

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?

Ishmael

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...
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Bernie

#2
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! :)

Pumaman

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.

00jon00

Thanks guys...I'll try the stuff you said, and if it dosn't work then I'll re-post

00jon00

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  
---------------------------

00jon00

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.

Ytterbium

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.


Currently in production: Septigon

00jon00


Pumaman

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.

00jon00

I've been using AGS for awhile now, and I now quite a bit of scripting...I just can't get THIS to work?

a-v-o

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.


SMF spam blocked by CleanTalk