Ambiera ForumDiscussions, Help and Support. |
|
[ 1 2 ] Page 1 of 2 |
|
|||||
|
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 ! |
||||
|
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. |
||||
|
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. |
||||
|
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 ;) |
||||
|
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. |
||||
|
No , I didn't ; only found a way to restrict the type of characters. But if you can share your solution , please do , thanks ! |
||||
|
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'); 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. |
||||
|
Thanks ! I'll try it and report back asap. |
||||
|
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 |
||||
|
error message : behavior_overlayTyping.js:33:ReferenceError: ccbGetCopperCubeVariable is not defined Maybe the coppercube variable "reset" has to be declared beforehand ? |
||||
|
hm, strange... oh wait, are you using the webgl target? |
||||
|
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; } |
||||
|
tested in OpenGL and .exe |
||||
|
you misplaced a bracket in there... behavior_overlayTyping.prototype.onAnimate = function(n, timeMs) how about now? |
||||
|
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 :) |
[ 1 2 ] Page 1 of 2 |
|