ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator help with in coppercube js
person icon
noddle
Registered User
Quote
2026-08-01 06:22:52

i made so that when a scene begins it ccbGetCopperCubeVariable("orgs") and when clicked on the thing it ccbSetCopperCubeVariable("orgs", +1) and repeted that 4 times for all the itens i nedded (it needes to be orgs = 4 to do actilon) but it doesnt work pls help

person icon
hadoken
Registered User
Quote
2026-08-01 09:52:17

try

ccbSetCopperCubeVariable("orgs", ccbGetCopperCubeVariable("orgs") + 1);

person icon
okeoke
Registered User
Quote
2026-08-01 13:07:26

wrote:
try

ccbSetCopperCubeVariable("orgs", ccbGetCopperCubeVariable("orgs") + 1);

You need to cast to number first. Those variables are always stored as strings and you will get '1' + 1 which is '11' not 2.

person icon
hadoken
Registered User
Quote
2026-08-01 22:00:15

@okeoke is right my answer was too quick, use something like:
ccbSetCopperCubeVariable("orgs", Number(ccbGetCopperCubeVariable("orgs")) + 1);
or for strict integer value use
ccbSetCopperCubeVariable("orgs", parseInt(ccbGetCopperCubeVariable("orgs")) + 1);


person icon
gu9
Guest
Quote
2026-08-02 15:32:13

Background / context information:

The type (number, string) that ccbGetCopperCubeVariable() returns appears to depend on the content previously set by the user.

- If you use ccbGetCopperCubeVariable() BEFORE using ccbSetCopperCubeVariable() on a new variable, the variable appears to default to an empty string, which triggers the issue mentioned by okeoke.
hadoken's updated approach should cleanly counter this issue.

- If you initialize the variable somewhere via ccbSetCopperCubeVariable(), you can afterwards safely use hadoken's first chosen approach (without the type conversion via "Number" or "parseInt").
Example:
1) Add a behavior "Before first drawing do something" to the root node of the scene (optionally check AlsoOnReload to re-run this every time the scene is reloaded/restarted).
2) On this behavior, add an "Execute javascript" action to set your variable:
ccbSetCopperCubeVariable("orgs", 0);

For variables affected by the "Set or change a Variable" editor action:
- When you use "Set", the variable seems to be initialized as a string, even if you specify a number as a value. This always leads to the issue described by okeoke.
- However, when you use "Add" on the variable or initialize the variable via "Add", it seems to be treated as a number afterwards.

Relevant code excerpts from CopperLicht to show that ccbGetCopperCubeVariable() supports "type aware" output and maps internally stored numbers to the correct format:


CL3D.CopperCubeVariable = function()
{
this.Name = '';
this.StringValue = '';
this.ActiveValueType = 0; // 0=string, 1=int, 2=float
this.IntValue = 0;
this.FloatValue = 0.0;
}

function ccbGetCopperCubeVariable(varname)
{
var scene = CL3D.gScriptingInterface.CurrentlyActiveScene;

var var1 = CL3D.CopperCubeVariable.getVariable(varname, true, scene);

if (var1 == null)
return null;

if (var1.isString())
return var1.getValueAsString();

if (var1.isInt())
return var1.getValueAsInt(); //number type

if (var1.isFloat())
return var1.getValueAsFloat(); //number type

return null;
}



person icon
okeoke
Registered User
Quote
2026-08-02 16:18:27

- If you initialize the variable somewhere via ccbSetCopperCubeVariable(), you can afterwards safely use hadoken's first chosen approach (without the type conversion via "Number" or "parseInt").

Worth mentioning that if you set variable using coppercube action, not through JS api call it will always be string. I would explicitly cast anyway though:)

person icon
gu9
Guest
Quote
2026-08-02 16:22:22

Warning:
Be careful with parseInt() if the variable hasn't been initialized yet.
If ccbGetCopperCubeVariable("orgs") returns an empty string "",
parseInt("") results in NaN (Not a Number) (tested on the webGL build).
It is safer to use Number(), if you want to use that approach.


Create reply:










 

  

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


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






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