Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
could someone write a simple if/then script?

spicymilk
Registered User
Quote
2023-05-01 13:32:01

Could the script basically be If you press this button than this button won't register for "insert" ms please


Guest
Guest
Quote
2023-05-01 17:34:37

This behavior gets rid of the key repeating if that is what you want.


/*
<behavior jsname="behavior_OnKeyEvent" description="Define a key event">
<property name="KeyCode" type="int" default="32" />
<property name="Action" type="action" default="" />
<property name="Action" type="action" default="" />
<property name="PrintKeyCodes" type="bool" default="false" />
</behavior>
*/

behavior_OnKeyEvent = function () {
this.down = false;
};

behavior_OnKeyEvent.prototype.onAnimate = function () { };

behavior_OnKeyEvent.prototype.onKeyEvent = function (key, pressed) {
if (!this.down) {
if (this.PrintKeyCodes) {
print(key, pressed);
}

if (key == this.KeyCode) {
ccbInvokeAction(this.Action);
}

this.down = true;

} else if (!pressed) {
if (key == this.KeyCode) {
ccbInvokeAction(this.Action);
}

this.down = false;
}

};



Guest
Guest
Quote
2023-05-01 17:42:38

If you want the action of the key event to be delayed you can use the above extension with Niko's Do Later action from here:

https://www.ambiera.com/coppercu...


Guest
Guest
Quote
2023-05-01 17:45:49

Also to use the extension I posted you can check the box to print the key codes when you press the buttons. Then change the key code to whatever you need it to be. The default is 32 which is the spacebar.


spicymilk
Registered User
Quote
2023-05-02 02:44:09

thanks


hadoken
Guest
Quote
2023-05-02 08:47:43

thanks for the script @Guest,

small bug fixed version for working distinction between action down and action up:
/*
<behavior jsname="behavior_OnKeyEvent" description="behavior_OnKeyEvent">
<property name="KeyCode" type="int" default="32" />
<property name="ActionDown" type="action" default="" />
<property name="ActionUp" type="action" default="" />
<property name="PrintKeyCodes" type="bool" default="false" />
</behavior>
*/

behavior_OnKeyEvent = function () {
this.down = false;
};

behavior_OnKeyEvent.prototype.onAnimate = function () { };

behavior_OnKeyEvent.prototype.onKeyEvent = function (key, pressed) {
if (!this.down) {
if (this.PrintKeyCodes) {
print(key, pressed);
}

if (key == this.KeyCode) {
ccbInvokeAction(this.ActionDown);
}

this.down = true;

} else if (!pressed) {
if (key == this.KeyCode) {
ccbInvokeAction(this.ActionUp);
}

this.down = false;
}

};



Guest
Guest
Quote
2023-05-02 16:36:23

@Hadoken

Thanks. I didn't read the post afterward but now I see if you type certain words together in the forum it will exclude them. I knew about the hashtag issue. My original code has the distinction between the two actions. Have to be more careful in the future.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "?nternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact