Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-05-2005, 07:50 PM
ChibiChibiLuc ChibiChibiLuc is offline
Cookie Monster. :3
Join Date: Jan 2005
Location: Nova Scotia, Canada
Posts: 111
ChibiChibiLuc is on a distinguished road
Send a message via AIM to ChibiChibiLuc Send a message via MSN to ChibiChibiLuc
KeyPressed/KeyDown2 checks

I'm having a problem with KeyPressed and KeyDown2. It only exists in v3/4, not v2, so it might belong in the Bugs section.

When the 's' key is caught with KeyPressed, a system sends a trigger to another NPC. However, I only want it to send the trigger once, not multiple times.
Originally, I set a flag that says the key was pressed, then use a timeout to check for when the player lets go of the key. When the player lets go of the key, it unsets the flag.

This doesn't work. While I'm holding down the 's' key, it continually calls the KeyPressed function, but KeyDown2 returns it as not being pressed.

NPC Code:
function onKeyPressed(code,key) {
if (key == "s" && this.holding == false) {
findweapon("Blah").trigger("DoSomething",NULL);
this.holding = true;
setTimer(.05);
}
}

function onTimeout() {
if (this.holding == true) {
if (!keydown2(getkeycode("s"),false)) this.holding = false;
setTimer(.05);
}
}




EDIT: My bad, I was using keycode() instead of getkeycode(). Changing it to getkeycode() made it work properly. This might have something to do with the hammer bug on GK?

Last edited by ChibiChibiLuc; 09-05-2005 at 08:52 PM..
Reply With Quote
  #2  
Old 09-05-2005, 08:06 PM
Torankusu_2002 Torankusu_2002 is offline
'been round.
Torankusu_2002's Avatar
Join Date: Nov 2001
Posts: 1,246
Torankusu_2002 is on a distinguished road
i haven't scripted with GS2 yet but for the most part i understand what you are trying to do.

but, I think you might also have to check for the keypressed if you want to check for the keydown2, not do them at different times and use a timeout and check the the this. to tell if to check if the key is pressed.

I've never had the problem you're having with keypressed.

example in newfeatures:
NPC Code:

if (keypressed) {
code = strtofloat(#p(0));
if (code==keycode(1,false)) message on;
else if (code==keycode(2,false)) message off;
}


i know it's keycode, but it might be of some use to you too?
__________________
torankusu's
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.