Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
IMMUTABLE VARS IN CC ?

DouweDabbe
Guest
Quote
2022-02-04 02:42:23

i do the following to create a status dependent click:


myGame.js: (this is optional)
myInt = 0;

myGame.ccb:
scene1 --> before first draw --> execjs --> myInt = 0;
2DOverlay --> whenClicked --> execJS -->
var tmp = 2;
ccbSetCCVar(myInt, tmp);
// oke myInt = 2 now
3DMesh --> whenClicked --> action_TiledClick() -->
Here I also try var tmpInt = ccbGetCCvar(myInt);
print("debug0 myInt="+myInt);
if (myInt == 0)
// change material texture of 3DMesh to tex1
if (myInt == 1)
// change material texture of 3DMesh to tex2
etc
if (myInt == 2)
// change material texture of 3DMesh to tex3
etc
// here never oke because
// myInt enters action as 2 but
// at if statements gets reset to 0 zero.

It seems i can not change myInt in a setup like this , but only temporarily.

what am i doing wrong here ???


just_in_case
Moderator
Quote
2022-02-04 15:12:09

What you are doing wrong in there is you are confusing yourself with javascript variables and CopperCube variables.

you have however defined the ("myInt") as a coppercube variable when clicked on the 2D overlay.

but when you are clicking on the 3D object, you are calling its value in a javascript variable ("tmpInt") and checking the conditions with the CopperCube variable ("myInt").
while you need to check the condition with the javascript variable.

So to fix the issue, you either need to change the ("myInt") in your IF conditions to ("tmpInt") or you can simply replace

var tmpInt = ccbGetCopperCubeVariable("myInt");


with

var myInt = ccbGetCopperCubeVariable("myInt");



now you can assign value to CC variable ("myInt") to either 0,1 or 2, whenever you want in your game, and they will change the texture accordingly.

Also in your before first drawing you are setting up javascript variable not a CopperCube variable, you need to set Coppercube variable there.

you can use the inbuilt action "set or change a variable"
Vriable name = myInt
value = 0

and you are good to go, you need to change CC variable whenever you want to update "myInt" not the javascript variable.

hope that helps.



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