Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
How would I achieve something like this in Script/Coppercube/Java please? I know I can do it without coding - but it will take forever to do - I've done it twice before, for all 195 countries, and then accidentally lost the work ![]() var a = ccbGetCopperCubeVariable($Country$); var s = ccbGetSceneNodeFromName("Country(Stats)"); if (a == "1"), ccbSetSceneNodeProperty(s, "Text", AFGHANISTAN); if (a == "2"), ccbSetSceneNodeProperty(s, "Text", ALBANIA); if (a == "3"), ccbSetSceneNodeProperty(s, "Text", ALGERIA); if (a == "4"), ccbSetSceneNodeProperty(s, "Text", ANDORRA); if (a == "5"), ccbSetSceneNodeProperty(s, "Text", ABGOLA); if (a == "6"), ccbSetSceneNodeProperty(s, "Text", ANTIGUA & BARBUDA); if (a == "7"), ccbSetSceneNodeProperty(s, "Text", ARGENTINA); if (a == "8"), ccbSetSceneNodeProperty(s, "Text", ARMENIA); if (a == "9"), ccbSetSceneNodeProperty(s, "Text", AUSTRALI); if (a == "10") ,ccbSetSceneNodeProperty(s, "Text", AUSTRIA); Obviously it doesn't work - it just says "Syntax Error". I checked W3chool -but I can't see how to convert it to something that will work with Coppercube's API..... Their example is... <h2>JavaScript if</h2> <p>Display "Good day!" if the hour is less than 18:00:</p> <p id="demo">Good Evening!</p> <script> if (new Date().getHours() < 18) { document.getElementById("demo").innerHTML = "Good day!"; } </script> I kinda know what I want to do, just don't know how to do it or how to learn how to do it. If it's not possible using Coppercube's API, I'll just do it again with non-coding using every few seconds, if variable = 1,change 2D overlay Thanks. |
||||
|
i would use ARRAY.. store countries list into array: //On before draw (execute javascript) //List of countries in array. country=[]; country[1]="Germany"; country[2]="Canada"; country[3]="India"; country[4]="USA"; etc.. Then i would execute javascript on each 100ms (or whatever interval you need) var a = ccbGetCopperCubeVariable("CountryID"); //number var nodeptr = ccbGetSceneNodeFromName("2dOverlay"); ccbSetSceneNodeProperty(nodeptr, 'Text', country[a] ); There is no need for IF statement at all. if you want to use IF statement then: var a = ccbGetCopperCubeVariable("CountryID"); //number var nodeptr = ccbGetSceneNodeFromName("2dOverlay"); if(a==1) { ccbSetSceneNodeProperty(nodeptr, 'Text', "Germany" ); } etc.. |
||||
|
Nice one Sven! I'll give it a try and use the ARRAYs. Appreciate your help! Thank you. |
||||
|
You get all countries list here: https://www.html-code-generator.com/javascript/array/country-names it generates you the array of countries :D |
||||
|
Thanks again Sven. Not sure how to get Arrays the working but will try using IF statements instead. |
||||
|
Same error with the If statements. I'll just do it the long way with individual actions. F****ing dyslexia. ![]() |
||||
|
send me your script so i can see where you are doing error.. i can make script for you if you want (its simple script so doesnt take long to make) Here: https://drive.google.com/file/d/... |
||||
|
Thank you for doing that Sven! Yours works perfectly. When I tried to do it myself, it doesn't work - it says "syntax error:syntax error: Script 3: Reference Error: Country is not defined." Would you mind trying to find what I'm doing wrong please? Although they're just a few lines of code, I've obviously managed to make a mismatch/typo error between the 2 scripts. Here's my ccb file... https://drive.google.com/file/d/... Thank you. |
||||
|
Error @line 108: Country107[]="Maldives (Male)"; should be Country[107]= i recommend you to use this site: https://esprima.org/demo/validat... Put your javascript in box and it tells where error is.. error you made is so tiny but hard to discover without proper methods :D Also i recommend you to use Notpad++ to write code.. if file you write has .js extension then code will be colored and its simple to detect errors visually.. later just copy code from it to coppercube editor. |
||||
|
How would this work??? To move a player from one location to another, how would I write that, ccbAICommand moveto code: NM?" as an example. Would I write that right after the code was declared {name: "Colombia",code: "CO"}, //ccbAICommand? moveto code:CO?? // between each line??? or after the whole array??? {name: "Comoros",code: "KM"}, {name: "Congo - Brazzaville",code: "CG"}, //moveto code "KM" //moveto code "CG" |
||||
|
Thank you Sven! Nice one. Appreciate your help. |
||||
|
Yay! Works like a charm. Thank you for teaching me how to use arrays - makes sense - that will save me a lot of time in the future. |
||||
|
@VP, I am glad that you started in scripting, it will ease out the work for you a lot. and you will be able to create amazing stuff with scripting. |
||||
|
Thanks, yes - I think scripting is the best way forward for me. I'll take the time to get used to it and explore the API. |
|