Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
2D Overlay Dynamic Text

cyril
Registered User
Quote
2012-11-09 13:36:23

Hi,

I know this topic has already been discussed, but I still don't understand.
I want to put a variable in a 2D Text Overlay and dynamically change.

For a variable "name" for example, I put "$name$" in Text area ? ($=sharp sign)
And how to change it ? name="toto" ? What is the exact syntax ?

In Flash AS3, no problem, I use Flash Text Area, no Copper Text.
My question is for CopperCube only, and JavaScript/CopperCube (for windows).

Thanks !
Cyril


erik
Registered User
Quote
2012-11-10 06:16:58

For changing the text, you can use the "Change 2D Overlay Text" action. If you want to show the content of a variable in it, yes, that's the right syntax. (See docs: http://www.ambiera.com/coppercub...). Changing a variable is done using the "Set or change a Variable" action. Note that in there, you must not use the $ syntax.


cyril
Registered User
Quote
2012-11-10 10:33:19

Thank you very much. OK
But from a Java Script, how it works ?
I want to change Text Area from a file text (for dialog for example).
If I want not use the Set Variable in Copper ?


erik
Registered User
Quote
2012-11-10 16:37:08

Hm, do you mean JavaScript in the Windows or Mac OS X target, or in WebGL? because those are two different ones.


cyril
Registered User
Quote
2012-11-10 17:44:23

JavaScript for Windows...


niko
Moderator
Quote
2012-11-11 20:02:34

You should be able to set the text using this code:


var s = ccbGetSceneNodeFromName("theNameOfYourOverlay");
ccbSetSceneNodeProperty(s, "Text", "some new text");


This should even work using the 'Execute Javascript' action. For details, see the javascript docs here: http://www.ambiera.com/coppercub.... You are probably also interested in the function ccbGetCopperCubeVariable() then.

hope this helps!


techno-valley
Registered User
Quote
2012-11-11 22:16:45

how to use the ccbSetCopperCubeVariable(varname, value) and ccbGetCopperCubeVariable(varname, value) commands

I used the following command in script as follow


var box = ccbSetCopperCubeVariable(state,up)



When using the $state$ in change 2D text it show $state$

and it give the following error in the debug console :


CopperCube Debug Console
script:ReferenceError: script is not defined



I noticed that when using your script above It always run directly when I launch the executable directly not when passing to execute java script

Does this mean that the script always launch when exe launch ?
How to launch when just calling the script ?


niko
Moderator
Quote
2012-11-14 07:26:40

Not sure about that 'script' error. Maybe you have a .js file in the path where you saved your .ccb file, and it is named the same? Then CopperCube trys to run that one, and the error may be from there.

I think it's simpler to simply build the string you want to show yourself using JavaScript, like

var textToShow = "Hello " + someValue + " world!";
ccbSetSceneNodeProperty(s, "Text", textToShow);


No need to using CopperCube variables, if you don't want to. But you can, of course, like
var textToShow =  ccbGetCopperCubeVariable("NameOfYourVariable");



Zoo
Guest
Quote
2017-08-01 20:36:21

OrderedScore ="test";
var s = ccbGetSceneNodeFromName('Leaderboard');
ccbSetSceneNodeProperty(s, 'Text', OrderedScore);

The above is my code

Spits out an error, property does not exist:"Text"

@niko


Zoo
Guest
Quote
2017-08-01 20:43:22

ok this code works
var s = ccbGetSceneNodeFromName('Leaderboard');
ccbSetSceneNodeProperty(this.LastOverlayObject, 'Draw Text', true);
ccbSetSceneNodeProperty(s, 'Text', OrderedScore);


Create reply:


Posted by: (you are not logged in)


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