Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
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) |
||||
|
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
Again, you’re passing the wrong data because of the earlier issues. Here’s the corrected version:
|
||||
|
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… |
||||
|
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. |
||||
|
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. |
||||
|
Understood, thank you for your help! (I am sorry for not logging in for almost a whole month) |
||||
|
|