Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Not really sure how to describe what I mean properly - but when I get a value returned from an array - how would I then use it as a variable/value for visual-coding please? eg: arrays(before first draw............ defend[0]="Empty Slot"; defend[1]="03"; //Amazon Warrior defend[2]="15"; //Anubis defend[3]="10"; //Battle Toad defend[4]="15"; //Beholder defend[5]="15"; //Beserker If array defend = [3], set variable "defensescore" = 3. Thank you. |
||||
|
You mean something like this? var defend = []; |
||||
|
Yes, perfect! Thank you :) |
||||
|
Unfortunately, it's showing an error, probably something simple I did wrong. Before I dig deeper and start changing things blindly, can I ask if the ")" symbol meant to be there? Esprima syntax checker says Error: Line 1: Unexpected token ) eg: if (enemy)[0] == "Empty Slot") should it be: if (enemy)[0] == "Empty Slot" Here's an example of what I've done if anyone can spot what I've done wrong?...
Thank you. |
||||
|
Okay, I deleted the trailing brackets and fixed a few other typos I had made and have managed to get it working properly (I think), although it does give me the following error... [img]https://i.postimg.cc/T1tnKhNF/error.png[/mg] Everything appears to work as I want it to so far, but is the error something I should worry about or try to fix? Thanks. |
||||
|
|
||||
|
...sorry for the multiple posts, I fixed it. - I had entered "09" as one of the values, instead of just "9", without the zero. |
||||
|
Maybe I asked the wrong question... no matter what value the (enemy)[?] array is, it doesn't seem display the correct attackscore or defensescore - it's always showing attackscore=10, defensescore=5 for some reason.
In the above example, if enemy is 6 - should defensescore variable be == 16, and if enemy is 7, defensescore variable should change to 12? I don't understand why it's not setting the correct variable for attack/defend - nor do I understand where it's getting the 10/5 values from. If I can get this working properly, the main part of the game is done. Thank you. |
||||
|
Hmm. Your code should be like: if (enemy[6] == "6") //Black Dragon { ccbSetCopperCubeVariable("attackscore", 19); ccbSetCopperCubeVariable("defensescore", 16); ccbSetCopperCubeVariable("rune", 0); ccbSetCopperCubeVariable("spell", 0); ccbSetCopperCubeVariable("item", 0); }; The if statement won't work without the condition being in parentheses. Think of if statements like: if (condition) { // Do something }; Those parentheses are paramount. Sorry for the late reply. Week has be hectic. Hope this helps! |
||||
|
See here in your example from above:
This should be:
That extra parenthesis is preventing you from accessing the array index like you want. It takes some getting used to, but if you persist, you'll get it in no time. Persistence is key, however. |
||||
|
Ahhh, now I see it. Thank you! |
||||
|
Thanks Guest - unfortunately it's still not working. I'll have done something wrong again. I'll just do the whole thing as visual-code, using your variable setter and conditional action executor. I can make an action for each attack and defend-score variable. Thanks so much for all the replies. |
||||
|
You're welcome! Good luck on your project! |
||||
|
|