Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
changing 2doverlay variable from within click with custom js

Registered User
2022-11-02 20:23:23

dear community,

so far I've learned a lot reading some older threads -thanks.
now i ran into a weird problem and can't solve it myself. Any help or hint is very much welcome - thank you.

I'd like to change a 2doverlay variable from an on-click behaviour. this works great as long i use only values.

when I switch the "variabletype" to "variable" this action stops working for no reason, no log error. as soon I delete the initial "variable name" the log shows the missing var error.

"Space" = value driven test
"CTRL" = variable driven test
the test var is called "varexternal" with a value of 111111 and is set within the js "Before do something".

I'm pretty sure I'm missing out on all the fun here.

2022-11-02 21:25:09

@gree, you got some variable mismatch ongoing when declaring "varexternal" by using "Execute JavaScript" action for: varexternal = "11111111"; What you get by this is a variable with highest scope for custom user coded CopperCube javascript behaviors/actions. The downside of this global variable type is that it won't get recognized as a CopperCube variable for CC editor inbuild behaviors/actions.

solution: use "Set or change a variable" action instead to declare "varexternal" as you also did for "text".

Hope that helps.

2022-11-02 21:40:37

Registered User
2022-11-02 21:57:42

thx @hadoken for the note.
unfortunately this won't solve my issue...

In detail I'd need to pass some information from an "Execute JavaScript" entry to the 2doverlay.

a custom js code sets the date.time.
when a user triggers some actions; the date.time should be placed in the 2doverlay.

not sure how to pass any "Execute JavaScript" variable within coppercube. Is this possible?

Registered User
2022-11-02 22:04:21

Update: I've tested the following code but can't get it to work...

ccbSetCopperCubeVariable(varname, value)

Will set a CopperCube variable to a certain value. CopperCube variables can be set and changed using the Variable Actions in the editor.

Registered User
2022-11-02 22:46:16

Update: Rob is talking about this issue and offers a solution. Is this really the way of doing it?

I found this challenging - only took me like 5 hours to work out successfully...

This is my javascript code to get the internal data you want to then save under another name using the general Save or Load variable method:

var player=ccbGetSceneNodeFromName("Player1");
var curPos=ccbGetSceneNodeProperty(player,"Position");
var curTgt=ccbGetSceneNodeProperty(player,"Target");
var curFov=ccbGetSceneNodeProperty(player,"FieldOfView_Degrees");
var curHth = ccbGetCopperCubeVariable("");

You can now save the variables 'savePosition' etc etc and reload them, then update to the new loaded variables with this javascript:

var player=ccbGetSceneNodeFromName("Player1");
var savePosition =ccbGetCopperCubeVariable("savePosition");
var saveTarget =ccbGetCopperCubeVariable("saveTarget");
var saveHealth =ccbGetCopperCubeVariable("saveHealth");
ccbSetSceneNodeProperty(player,"Position", savePosition);
ccbSetSceneNodeProperty(player,"Target", saveTarget);

not sure the correct javascript for updating health so I just used standard variable menu: Set to variable 'saveHealth'

2022-11-02 23:18:39


passing values from javascript variables to CopperCube editor variables can easily be done with ccbSetCopperCubeVariable(varname, value) command, e.g. by adding the following to your "Execute JavaScript" action:

varexternal = "11111111";
ccbSetCopperCubeVariable("cc_varexternal", varexternal);

then you must not pass "varexternal" but the extra created CopperCube variable in this example named "cc_varexternal" (which then should have the same value as "varexternal") to your 2d overlay using the built-in "Change 2d overlay Text" action with $cc_varexternal$

without creating an extra CopperCube variable for the editor you could also go the other way round by changing your 2d overlay text also directly by using another "Execute JavaScript" action with this:

ccbSetSceneNodeProperty(ccbGetSceneNodeFromName("2D Overlay1"), "Text", varexternal);

Registered User
2022-11-02 23:47:09

i did a quick test and it works.
that's it! the missing piece :)

thanks @hadoken - my hero of the day!

Create reply:

Posted by: (you are not logged in)

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




Possible Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]



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