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

key is pressed..

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




Joined: 12 Mar 2003
Posts: 359

PostPosted: Mon May 11, 2009 5:31 pm    Post subject: key is pressed.. Reply with quote

I have a script that uses "if (key is pressed (key:space))", but I don't want the player to be able to cheat by simply holding down the space key. So, simply put, how can i make it so that the player must repeatedly press the space rather than holding down the button.

The purpose of this is pretty much a timed action sequence, and I only require the use of the spacebar. And much of the duration between key presses are very short (shortest duration is 4 ticks).

Any help would be greatly appreciated.
Back to top
View user's profile Send private message
Pepsi Ranger
Reality TV Host




Joined: 05 Feb 2003
Posts: 493
Location: South Florida

PostPosted: Mon May 11, 2009 6:31 pm    Post subject: Reply with quote

You could break the loop after every keypress and force a certain wait time before restarting the script.

And use a global variable to keep track of how often the script is run, so that when you hit the magic number to move on, you can bypass the rerun completely.

Example:

Code:
global variable (1,runner)

script,Press Me,begin
variable (loop)
if (runner<=5) then(
set variable (loop,true)
while (loop) do(
if (key is pressed (key:SPACE)) then(
#do whatever
set variable (loop,false)
)
wait (1)
)
wait (5)
increment (runner,1)
Press Me
)
if (runner>>5) then(
exit script
)
end


You'll want to toy with this a bit, but it should be enough to point you in the right direction.
_________________
Progress Report:

The Adventures of Powerstick Man: Extended Edition

Currently Updating: General sweep of the game world and dialogue boxes. Adding extended maps.

Tightfloss Maiden

Currently Updating: Chapter 2
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Spoon Weaver




Joined: 18 Nov 2008
Posts: 421
Location: @home

PostPosted: Mon May 11, 2009 8:34 pm    Post subject: Reply with quote

What I like to do is similar to pepsi's script but without the break in the loop, since the loop can be controlling other stuff.

Basically, I have the if key is press statement set a variable to 1 or on if the key is pressed, and use an else function to set the same variable to 0 or off
then also require the variable be off for the statement to be true.

which would look something like this.



Code:
global variable (1,runner)

script,Press Me,begin
variable (loop)
set variable (loop,true)

while (loop) do(
if (key is pressed (key:SPACE),and,runner==0) then(
runner:=1
#do whatever
)else(runner:=0)
wait (1)

)
end
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Mon May 11, 2009 10:04 pm    Post subject: Reply with quote

There's a way easier way. Check out 'Plot:Keyval'.

The problem with keyval is that it will eventually register true if the player holds down the button for a second. This is the same phenomenon as when you hold down a button while typing. So this may or may not work for your purposes... but if it does, it's by far the easiest way.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Tue May 12, 2009 7:55 am    Post subject: Reply with quote

I wanted to add another bit to the keyval return value to indicate whether this is a brand new keypress - in fact, I already added it to the internal array, but it's removed from the keyval return value, because I don't know whether it would break anyone's scripts :( We'd need some sort of work around to be safe.

Also, it's about time that we added a replacement for keyispressed, since that's not what people want most of the time anyway: they usually want (keyval(key), and, 2)

Maybe we could add a new command that does both, such as:

keypress (scancode)
True if typematic keypress event; ((keyval(scancode), and, 2) == 2)
keypress (scancode, depressed)
Returns true if the key was newly pressed this tick
keypress (scancode, released)
Returns true if the key was released this tick
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Tue May 12, 2009 8:25 am    Post subject: Reply with quote

Quote:
Also, it's about time that we added a replacement for keyispressed, since that's not what people want most of the time anyway


Not true. When I say keyispressed(key:right), I mean keyispressed(key:right).
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Thu May 14, 2009 1:28 am    Post subject: Reply with quote

Well, you obviously know what you want. Maybe not a majority of the time, but continuously, I see people using keyispressed when they shouldn't, to implement a menu or use an NPC, and then often throw in a whole lot of illogical waits. Over-sensitive scripted menus/selections are everywhere.

I should have been clearer: not a replacement, but an alternative. keyval would be obsolete, as keypress and keyispressed would cover all cases between them
_________________
"It is so great it is insanely great."
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