Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (TipmyPip, AndrewAMD, Quad, aliswee, degenerate_762), 970 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Holding arrow key down #470878
02/10/18 15:43
02/10/18 15:43
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
I have an inventory transfer system in place, in case the player wants to loot a dead body, or search a treasure chest, both the player's and the other entity's inventory bags display on the screen, and the player can click and drag items from one inventory bag to the other. When this happens, the game will ask the player how much of the item in question the player wants to transfer, and it will show the maximum amount of that item that can be transferred at that time. The player can then press the down arrow to decrease the amount, or the up arrow to increase the amount.

However, lets say there is a lot of the item in question to transfer. Lets say there is 100 of them. As my game program is right now, the player would have to push the up or down arrow key one button push at a time each time to make the counter increment or decrement by one. I really want to make it so that the player can hold down the down or up arrow key to change the amount automatically and faster.

This is what I have so far:

Code:
void increaseQntTransfer()
{
   itm_qnt_ent_from += 1;
	
   if(itm_qnt_ent_from > maxItmQntEntFrom) // KEEPS ITEMS BEING
      //    TRANSFERRED FROM GOING OVER MAXIMUM AMOUNT.
   {
      itm_qnt_ent_from -= 1;
   }
}

void decreaseQntTransfer()
{
   itm_qnt_ent_from -= 1;
	
   if(itm_qnt_ent_from < 0) // KEEPS ITEMS BEING TRANSFERRED FROM
      //    GOING BELOW ZERO.
   {
      itm_qnt_ent_from += 1;
   }
}		

void transferProcess()
{	
   ...

   on_cuu = increaseQntTransfer;
   on_cud = decreaseQntTransfer;

   ...
}



I tried putting a while(on_cud) loop around the...
Code:
itm_qnt_ent_from -= 1;


...in the decreaseQntTransfer() function, with a wait(1) at the end, but when I pressed the down arrow to reduce the amount to transfer, it just kept reducing and would not stop, even when I took my finger off the down arrow key.

I am afraid of creating an infinite loop. Can anyone give me advice on how to make it so that the player can press and hold down the up or down arrow key to make the amount to transfer change faster, and then if the player takes the finger off of these keys, the amount to transfer stops changing, and remains where the number has left off?

Last edited by Ruben; 02/10/18 15:45.
Re: Holding arrow key down [Re: Ruben] #470886
02/10/18 21:48
02/10/18 21:48
Joined: Jul 2014
Posts: 72
D
DriftWood Offline
Junior Member
DriftWood  Offline
Junior Member
D

Joined: Jul 2014
Posts: 72
Look at Keys.c and ask yourself how many times the on_cud is starting a new instance of that function. In one second it could fire 60 instances.
Simply use a time to limit it to once every 1/2 a second.
Look at examples from the past in the forum about keys and time limit. --Hint combo keys post.
Look at proc_kill.
As a final step some one will most likely fix it minutes for money.

Last edited by DriftWood; 02/10/18 21:49.
Re: Holding arrow key down [Re: DriftWood] #470887
02/11/18 05:49
02/11/18 05:49
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thank you DriftWood. Thanks to you I learned the difference between on_cud and key_cud, and I solved my issue. I really appreciate it.


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