Need help with Input commands

Started by Nicant, October 31, 2015, 08:42:51 PM

Previous topic - Next topic

Nicant

I need help with my new map i'm making. I'm trying to make a button type unit that when you press a button on the keyboard it does something. The code below shows what i am trying to do. # OreHarvButton.crpl
# Created on: 10/31/2015 4:07:08 PM
# ------------------------------------------
#Position your mouse where you want to place a unit and then press 1 on the number pad.
GetMousePosition ->x ->y
if (GetKeyUp("Keypad1"))
# The unit should be created but does not get created. I don't know if it is the code above or below. so please help
"CRPLCORE" <-x <-y CreateUnit ->unit
<-unit "OreHarvester.crpl" AddScriptToUnit
<-unit "main" "Custom43" SetImage
endif








If anyone can help me in any way, please tell me!  :)
CW4 hype!!

hbarudi

If (GetKey("Keypad1"))


Should not be GetKeyUP why up?

warren

"Keypad1" probably only refers to the number key on the pad that 50% of modern keyboards do not come with.

getKeyDown, getKey and getKeyUp all do different things. GetKeyUp is probably the correct choice

Nicant

#3
Quote from: warren on November 01, 2015, 05:28:57 AM
"Keypad1" probably only refers to the number key on the pad that 50% of modern keyboards do not come with.

getKeyDown, getKey and getKeyUp all do different things. GetKeyUp is probably the correct choice
Quote from: hbarudi on November 01, 2015, 02:09:15 AM
If (GetKey("Keypad1"))


Should not be GetKeyUP why up?

I was trying everything possible and none of the choices work. I tried Getkey, Getkeydown, and Getkeyup. Also i have a keyboard with a number pad.

CW4 hype!!

Grayzzur

#4
First, GetMousePosition returns X then Y to the stack, so you'd want to save off Y first, then X, or you reverse them.

Second, GetMousePosition returns the mouse in PixelCoordinates, but CreateUnit expects CellCoordinates. This will put the right values in 'x' and 'y' to use CreateUnit under the mouse cursor:
GetMousePosition PixelToCell ->y ->x

The GetKeyUp/Keypad1 thing should be working fine.

Last item, the other piece of the issue is that a CRPLCORE created by CreateUnit simply has no image by default. The unit is probably being created but invisible (and waaaay off the screen with the wrong coordinates). Add the following after your CreateUnit command to see if they start showing up:
<-unit "main" "Default" SetImage
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

Nicant

Quote from: Grayzzur on November 01, 2015, 03:12:15 PM
First, GetMousePosition returns X then Y to the stack, so you'd want to save off Y first, then X, or you reverse them.

Second, GetMousePosition returns the mouse in PixelCoordinates, but CreateUnit expects CellCoordinates. This will put the right values in 'x' and 'y' to use CreateUnit under the mouse cursor:
GetMousePosition PixelToCell ->y ->x

The GetKeyUp/Keypad1 thing should be working fine.

Last item, the other piece of the issue is that a CRPLCORE created by CreateUnit simply has no image by default. The unit is probably being created but invisible (and waaaay off the screen with the wrong coordinates). Add the following after your CreateUnit command to see if they start showing up:
<-unit "main" "Default" SetImage

YES! Thank you very much! It's finally working! Do you want to be credited in the map that i am making for helping me with the button? https://knucklecracker.com/forums/index.php?topic=19490.0
CW4 hype!!

Grayzzur

Credit is not necessary, but thank you.

Playing the map will be reward enough.  8)
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

Nicant

Quote from: Grayzzur on November 01, 2015, 03:32:37 PM
Credit is not necessary, but thank you.

Playing the map will be reward enough.  8)
ok, but thanks again!
CW4 hype!!