Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
4 registered members (AndrewAMD, Quad, soulman3, Ayumi), 675 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
wait for key release? #160144
10/10/07 12:25
10/10/07 12:25
Joined: Nov 2005
Posts: 1,007
jigalypuff Offline OP
Serious User
jigalypuff  Offline OP
Serious User

Joined: Nov 2005
Posts: 1,007
i want this function to run only when the key has been pressed and released, but it won`t work and i`m stuck as to why, all help greatly appreciated.
Code:

function fnct_impulse(w,s)
{
while(1)
{
if ((key_w == 1)&& (key_w == 0))///wait till key is released
{
ship_speed.x + = 100;///increase bmap window by 100
}
if ((key_s == 1) && (key_s == 0))
{
ship_speed.x - = 100;
}
wait(1);
}
}




Why does everyone like dolphins? Never trust a species which smiles all the time!
Re: wait for key release? [Re: jigalypuff] #160145
10/10/07 12:30
10/10/07 12:30
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline
User
bstudio  Offline
User

Joined: Aug 2006
Posts: 652
Netherlands
if ((key_w == 1)&& (key_w == 0))///wait till key is released

this is not good, cause it will never be called. You check if it's pressed, but it must be not pressed at the same time, that can never happen.

Code:

while(1)
{
if (key_w == 1)
{
while(key_w == 1)
{
wait(1);
}
ship_speed.x + = 100;///increase bmap window by 100
}
if (key_s == 1)
{
while(key_s == 1)
{
wait(1);
}
ship_speed.x - = 100;
}
wait(1);
}


You can try this, dunno if it works though.


BASIC programmers never die, they GOSUB and don't RETURN.
Re: wait for key release? [Re: bstudio] #160146
10/10/07 12:34
10/10/07 12:34
Joined: Nov 2005
Posts: 1,007
jigalypuff Offline OP
Serious User
jigalypuff  Offline OP
Serious User

Joined: Nov 2005
Posts: 1,007
dude that works great thanks, one thing is it possible to fix it so it can only go to a max of 400? and a minimum of 0? i noticed if i keep pressing it it`ll keep counting up, i have a bmap for this which shows the speed and the max is 400, 0 is stopped obviously lol.


Why does everyone like dolphins? Never trust a species which smiles all the time!
Re: wait for key release? [Re: jigalypuff] #160147
10/10/07 12:44
10/10/07 12:44
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline
User
bstudio  Offline
User

Joined: Aug 2006
Posts: 652
Netherlands
Code:

while(1)
{
if (key_w == 1 && ship_speed.x>=0 && ship_speed.x<=400)
{
while(key_w == 1)
{
wait(1);
}
ship_speed.x + = 100;///increase bmap window by 100
}
if (key_s == 1 && ship_speed.x>=0 && ship_speed.x<=400)
{
while(key_s == 1)
{
wait(1);
}
ship_speed.x - = 100;
}
wait(1);
}


this should work

Last edited by bstudio; 10/10/07 12:46.

BASIC programmers never die, they GOSUB and don't RETURN.
Re: wait for key release? [Re: bstudio] #160148
10/10/07 12:58
10/10/07 12:58
Joined: Nov 2005
Posts: 1,007
jigalypuff Offline OP
Serious User
jigalypuff  Offline OP
Serious User

Joined: Nov 2005
Posts: 1,007
still a problem, it works ok but a small bug, if you press w or s one time to many, it won`t go back down, like it gets stuck, the trouble with this is in game it is easy to hit a key to many times, and then the player is stuck on either top speed or left unable to move, and thanks for this help btw, your totaly saving my hair from being ripped out.


Why does everyone like dolphins? Never trust a species which smiles all the time!
Re: wait for key release? [Re: jigalypuff] #160149
10/10/07 13:06
10/10/07 13:06
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline
User
bstudio  Offline
User

Joined: Aug 2006
Posts: 652
Netherlands
with ship_speed.x, do you start with 0? Cause else it will be 401 the last time and it won't go back indeed. Or you just do this:
Code:


while(1)
{
if (key_w == 1 && ship_speed.x<=400)
{
while(key_w == 1)
{
wait(1);
}
ship_speed.x + = 100;///increase bmap window by 100
}
if (key_s == 1 && ship_speed.x>=0)
{
while(key_s == 1)
{
wait(1);
}
ship_speed.x - = 100;
}
wait(1);
}



That should solve it, but it can be above 400 because the check is done first and if it's still under 400 (like 399) it will still add 100


BASIC programmers never die, they GOSUB and don't RETURN.
Re: wait for key release? [Re: bstudio] #160150
10/10/07 13:16
10/10/07 13:16
Joined: Nov 2005
Posts: 1,007
jigalypuff Offline OP
Serious User
jigalypuff  Offline OP
Serious User

Joined: Nov 2005
Posts: 1,007
well i have a var 300; this is so the bmap will have one section filled up so it shows as one quarter.
here`s the bmap

so each section is 100, and it needs to go up to 400 and down to 0, i can`t think of any other way to achieve this at all.


Why does everyone like dolphins? Never trust a species which smiles all the time!
Re: wait for key release? [Re: jigalypuff] #160151
10/10/07 13:19
10/10/07 13:19
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline
User
bstudio  Offline
User

Joined: Aug 2006
Posts: 652
Netherlands
Hmmmm the code should work then, does it still get stuck with my current code?


BASIC programmers never die, they GOSUB and don't RETURN.
Re: wait for key release? [Re: bstudio] #160152
10/10/07 13:36
10/10/07 13:36
Joined: Nov 2005
Posts: 1,007
jigalypuff Offline OP
Serious User
jigalypuff  Offline OP
Serious User

Joined: Nov 2005
Posts: 1,007
yep is just needs two taps of the keys to get the bmap to move, thanks man


Why does everyone like dolphins? Never trust a species which smiles all the time!
Re: wait for key release? [Re: jigalypuff] #160153
10/10/07 13:38
10/10/07 13:38
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline
User
bstudio  Offline
User

Joined: Aug 2006
Posts: 652
Netherlands
np, good luck with your game


BASIC programmers never die, they GOSUB and don't RETURN.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1