ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > CopperCube Open discussion
forum topic indicator Scripting
person icon
winter_dev0001
Registered User
Quote
2025-07-10 23:41:10

Hello, I have a Syntax error in my script, (at least the coppercube debug console gave the error) but i put the same code in a Javascript validator and it was just fine.
The debug console keeps giving the error:"illegal character".
Can someone help pls?

source code


ccbGetCopperCubeVariable(kills)
var killOverlay = ccbGetSceneNodeFromName("killMonitor")
var numOfKills =`kills: ${kills}`

kills+=1

ccbSetSceneNodeProperty(killOverlay , "Text" , kills)

person icon
wing
Guest
Quote
2025-07-11 06:39:36

Let’s go over your lines one by one:
I
ccbGetCopperCubeVariable(kills)

Here you’re calling the function to get a variable - but you’re not assigning its result to anything. That’s the first problem. The second is that you’re passing in kills, which isn’t declared anywhere. From the rest of your code it looks like you mean to treat it as a non-string variable, but the important bit is that ccbGetCopperCubeVariable(...) takes the name of a global CopperCube variable as a string.
To fix this, you need to capture the value into something:
var numOfKills = ccbGetCopperCubeVariable("kills");


II
var numOfKills = `kills: ${kills}`

Here you’re trying to build a string, but you’re mis-referencing the variable. If you wanted to use CopperCube’s built-in string formatting, it’d look like "kills: $kills$", but honestly I wouldn’t recommend that approach in JS. You’ve already got direct access to the variable value via numOfKills.

III
kills += 1

You’re trying to increment kills, which (as we saw) isn’t defined.

IV

var killOverlay = ccbGetSceneNodeFromName("killMonitor")
ccbSetSceneNodeProperty(killOverlay , "Text" , kills)

Again, you’re passing the wrong data because of the earlier issues.

Here’s the corrected version:

// Find your text overlay node
var killOverlay = ccbGetSceneNodeFromName("killMonitor");
// Load the current kill count
var numOfKills = ccbGetCopperCubeVariable("kills");

// Increment it
numOfKills++;

// Save it back to the CopperCube variable
ccbSetCopperCubeVariable("kills", numOfKills);
// Update the on-screen text
ccbSetSceneNodeProperty(
killOverlay,
"Text",
"Kills: " + numOfKills
);


person icon
wing
Guest
Quote
2025-07-11 06:45:35

The actual "illegal character" error you’re getting is caused by this line:
var numOfKills = `kills: ${kills}`

To get rid of the error, you can simply rewrite it like this:
var numOfKills = "kills: ${kills}"

and the error will disappear.

However, your code will then run into another issue…

person icon
winter_dev0001
Registered User
Quote
2025-07-11 17:27:29

Thank you for your reply! And also thank you for fixing my script.
As for the last line of your reply, no it didnt. It works just fine.
thanks for the help again, have a good day.

person icon
wing
Guest
Quote
2025-07-11 18:54:40

That’s strange. Even after fixing the brackets, you’re still getting an error on this line "ccbGetCopperCubeVariable(kills)".
The reason is that you’re passing in a variable that’s not defined, and even if it were, it’s the wrong way to use this function.
Later in your code, you’re doing "kills += 1" which means you’re treating kills as an int or float. But ccbGetCopperCubeVariable expects a string with the name of the variable you want to get, not the variable itself.

person icon
winter_dev0001
Registered User
Quote
2025-08-09 19:46:53

Understood, thank you for your help!

(I am sorry for not logging in for almost a whole month)


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 |