Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Problem with running script when key is pressed

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
Onlyoneinall
Bug finder




Joined: 16 Jul 2005
Posts: 746

PostPosted: Sat Aug 12, 2006 9:54 pm    Post subject: Problem with running script when key is pressed Reply with quote

This script has a problem, but I don't know what it is. When the script is run, the character ends up getting stuck in the tile it advances to and it keeps moving (as in the animation), but the character just sits there and you can't open a menu. Is something wrong with it? How would I make a script if this one isn't correct, so that a character will run when you hold down a key?

Code:

script,Run,begin
if (key is pressed(key:Z))
then,begin
set hero speed(0,5)
end
else,begin
set hero speed(0,4)
end
end

_________________
http://www.castleparadox.com/gamelist-display.php?game=750 Bloodlust Demo 1.00

Back to top
View user's profile Send private message Send e-mail
TwinHamster
♫ Furious souls, burn eternally! ♫




Joined: 07 Mar 2004
Posts: 1352

PostPosted: Sun Aug 13, 2006 3:31 am    Post subject: Reply with quote

Apparently the guys who work on the engine decided to change 'key is pressed' to 'keyval' without updating the dictionary.

Keyval is the exact same thing as key is pressed.
Back to top
View user's profile Send private message Send e-mail AIM Address
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Mon Aug 14, 2006 1:14 pm    Post subject: Reply with quote

You should not change speed while the hero is moving. That causes it to become misaligned with the tiles, and gets you stuck. Try wrapping the code in an if block that checks to make sure the hero is not currently walking before changing the speed.

Code:

script,Run,begin
  if(hero is walking(0))
  else, begin
    if (key is pressed(key:Z))
    then,begin
      set hero speed(0,5)
    end
    else,begin
      set hero speed(0,4)
    end
  end
end



As for the key is pressed vs keyval, yes there is a change in the behaviour of key is pressed, but not one that could cause this problem

The new behavior of key is pressed is to return true or false depending on whether or not the key is being pressed. The documentation didn't change, because the old implementation of key is pressed did NOT really do exactly what the documentation said.

The old key is pressed (and the new keyval) does the following:

0 if not pressed
greater than 0 if pressed
greater than 1 on key-down and key-repeat

If you wanted to use keyval here, and take advantage of its original keypress detection, you would write:

Code:

script,Run,begin
  if(hero is walking(0))
  else, begin
    if (keyval(key:Z)>>1)
    then,begin
      set hero speed(0,5)
    end
    else,begin
      set hero speed(0,4)
    end
  end
end
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Onlyoneinall
Bug finder




Joined: 16 Jul 2005
Posts: 746

PostPosted: Wed Aug 16, 2006 12:42 pm    Post subject: Reply with quote

Awesome, now the script runs without much of an issue! Now I also understand better the "hero is walking" plotscripts command and such better as well. Thanks!
_________________
http://www.castleparadox.com/gamelist-display.php?game=750 Bloodlust Demo 1.00

Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group