Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
edit box extension

therickman
Registered User
Quote
2018-11-26 16:44:41

Hello , I'm using the edit box extension to add interactivity to the game.
The user types a word in a 2d overlay ( turned into edit box via extension) to open a door.
PROBLEM: the 2d overlay registers all key presses including arrows which are used for moving the character. So when it's time to enter the password there's no way to reset the 2d overlay beforehand ; it can be briefly set to a blank ( by setting the 2d overlay text) but as soon as you start typing again all the previous characters reappear… in edit box mode the text can't be reset. If anyone has a workaround for this, thank you !


niko
Moderator
Quote
2018-11-27 07:45:27

Ah, that's an interesting use case for that. If you still want to use that edit box, it would probably be best to extend it a bit to only react to the keys you want. It is probably just a few "if"s to be added into its code.


therickman
Registered User
Quote
2018-11-27 09:05:03

Hello Niko , thank you for answering.
That's what I'm going to ( try to ) do : I'm going to look for a javascript snippet of code that limits key presses to letters.

On a side note : allowing typing ( and checking user input ) could be very useful to extend the relevance of coppercube to the field of edutainment and education. ( serious games etc )

That's what I'm try to achieve ; I have just started though , but I will share my findings if other educators are interested to see how coppercube can be used for this.


therickman
Registered User
Quote
2018-11-27 13:52:43

Hurray !
I managed to modify the original javascript to get it to work !

For anyone interested, I replaced line 47 : key> 32 with

if (key >= 65 && key <= 90)

This limits the key to capital letters .

Now for someone who doesn't know programming ( that's me ) it feels good :)


Just a note : in the original javascript, small letters were displayed in the overlay as capital letters , and I couldn't change that any way ; I don't know if this is set in the javascript…

Now my password system works , even if it's only with capital letters but that's ok for now.


Note 2 : I was really lucky , because the rest of the javascript is very obscure to me ;)


tim12345
Guest
Quote
2018-11-27 19:32:09

hi, did you find a way to reset it? i just looked into the code out of curiosity and found a simple way to reset it.


therickman
Registered User
Quote
2018-11-27 20:34:36

No , I didn't ; only found a way to restrict the type of characters.
But if you can share your solution , please do , thanks !


tim12345
Guest
Quote
2018-11-27 20:49:58

ok, well i'm not sure how your project is set up but basically i put this code into the script:

var reset= ccbGetCopperCubeVariable('reset');
if(reset==1){
this.Text = this.Text.substring(0, 0);
ccbSetSceneNodeProperty(this.LastOverlayObject, 'Text', " ");
ccbSetCopperCubeVariable('reset',0);
}


and i put it right after the line:
behavior_overlayTyping.prototype.onAnimate = function(n, timeMs)
{
so it is at the beginning of that function...

and then in your project, when you want to reset the text, just have something like a 'click' trigger the action 'set a variable' --> and set variable "reset" to 1.

the script should then catch that, reset the text, and change the 'reset' variable back to 0, so you can reset it again when you click again. something like that might work.


therickman
Registered User
Quote
2018-11-27 21:12:24

Thanks ! I'll try it and report back asap.


therickman
Registered User
Quote
2018-11-28 10:55:27

Hello ,
so I tried your code but it blocks the typing behaviour apparently , because no text is displayed at all when I type and if I press the trigger key ( here :space) well nothing happens


therickman
Registered User
Quote
2018-11-28 11:32:37

error message :
behavior_overlayTyping.js:33:ReferenceError: ccbGetCopperCubeVariable is not defined

Maybe the coppercube variable "reset" has to be declared beforehand ?


tim12345
Guest
Quote
2018-11-28 11:43:44

hm, strange... oh wait, are you using the webgl target?


therickman
Registered User
Quote
2018-11-28 12:53:22

I had misplaced the code apparently , but now I placed it as you mentioned, but I get " syntax error"


This is where the code is inserted

// called every frame.
// 'node' is the scene node where this behavior is attached to.
// 'timeMs' the current time in milliseconds of the scene.
// Returns 'true' if something changed, and 'false' if not.
behavior_overlayTyping.prototype.onAnimate = function(n, timeMs)
var reset= ccbGetCopperCubeVariable("reset");
if(reset==1){
this.Text = this.Text.substring(0, 0);
ccbSetSceneNodeProperty(this.LastOverlayObject, 'Text', " ");
ccbSetCopperCubeVariable("reset",0);
}

{
this.LastOverlayObject = n;

return true;
}


therickman
Registered User
Quote
2018-11-28 13:13:05

tested in OpenGL and .exe


tim12345
Guest
Quote
2018-11-28 13:42:41

you misplaced a bracket in there...

behavior_overlayTyping.prototype.onAnimate = function(n, timeMs)
{
var reset= ccbGetCopperCubeVariable("reset");
if(reset==1){
this.Text = this.Text.substring(0, 0);
ccbSetSceneNodeProperty(this.LastOverlayObject, 'Text', " ");
ccbSetCopperCubeVariable("reset",0);
}

this.LastOverlayObject = n;

return true;
}


how about now?


therickman
Registered User
Quote
2018-11-28 13:59:35

yes , now it works ! thanks a lot !
Works in .exe and also OpenGL;

This is great!

( note to self : go back to studying those javascript tutorials asap :)



Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Int?rnational" (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