Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   keydown checks on two keys at once (https://forums.graalonline.com/forums/showthread.php?t=134265318)

sssssssssss 12-18-2011 11:53 PM

keydown checks on two keys at once
 
PHP Code:

if (keydown(0) && keydown(1)) {
            
player.1;
            
player.1;
          } 

This isn't working, but I need to know if there is a way to check if, say you had pressed up, and was holding it, then pressed right, and do something with that combination. This is during a freezeplayer too.

Tolnaftate2004 12-19-2011 12:06 AM

Quote:

Originally Posted by sssssssssss (Post 1678546)
PHP Code:

if (keydown(0) && keydown(1)) {
            
player.1;
            
player.1;
          } 

This isn't working, but I need to know if there is a way to check if, say you had pressed up, and was holding it, then pressed right, and do something with that combination. This is during a freezeplayer too.

Well, this code is a no-op and will likely be removed by dead code elimination, you probably mean, e.g.,
PHP Code:

player.+= 


sssssssssss 12-19-2011 12:07 AM

Yeah I had that and tried with just a + just for kicks in hopes. I didn't try while instead of if, ill see if that works.

sssssssssss 12-19-2011 12:24 AM

PHP Code:

while (keydown(0)) {
            if (
keydown(1)) {
              
player.+= .1;
              
player.-= .1;
            }
          } 

using this is also getting nowhere. It just stops what it was doing before most of the time, and on the rare occasion that it does work it pushes the player heavily around the gmap. I tried using something like .0001 as well, and the closest thing was .001 but it still pushed me a good 15 tiles. Seems like its doing some kind of opposite direction as well. :/ I'm stuck, probably something stupid and simple as usual too that I'm just not seeing. My logic is out of whack lately.

fowlplay4 12-19-2011 12:29 AM

It stops working because it hits the 'loop limit'. Your code was essentially doing:

PHP Code:

while (true) {
  if (
keydown(1)) stuff();


You would have to use a sleep in the while loop if you want there to be a chance for your keydown condition to change.

You may be right about your logic being out of whack because you probably don't even need to use the conditions that you're specifying. Try this code out:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
disabledefmovement();
  
setTimer(0.05);
}

function 
onTimeout() {
  if (
keydown(0)) player.-= 0.1;
  if (
keydown(1)) player.-= 0.1;
  if (
keydown(2)) player.+= 0.1;
  if (
keydown(3)) player.+= 0.1;
  
setTimer(0.05);



sssssssssss 12-19-2011 12:37 AM

Yep that did it. Can't believe I didn't try that. -_-

Happens every time I stop making website and using C. Not going to stop anymore lol.


All times are GMT +2. The time now is 12:28 PM.

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