ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator how to create a variable using an array
person icon
veganpete.
Registered User
Quote
2024-06-04 00:30:43

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.

person icon
Guest
Guest
Quote
2024-06-04 00:49:01

You mean something like this?
var defend = [];

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 (defend[2] == "15")
{
ccbSetCopperCubeVariable("defensescore", 3);
};

print(ccbGetCopperCubeVariable("defensescore"));


person icon
vp
Guest
Quote
2024-06-04 22:38:49

Yes, perfect! Thank you :)

person icon
VP
Guest
Quote
2024-06-06 15:10:52

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?...

 
if (enemy)[155] == "155") //Knight
{
ccbSetCopperCubeVariable("attackscore", 12);
ccbSetCopperCubeVariable("defensescore", 10);
ccbSetCopperCubeVariable("rune", 2);
ccbSetCopperCubeVariable("spell", 155);
ccbSetCopperCubeVariable("item", 155);
};


Thank you.

person icon
VP
Guest
Quote
2024-06-06 16:41:42

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.

person icon
vp
Guest
Quote
2024-06-06 16:42:26

embedded external image
🔎︎


person icon
vp
Guest
Quote
2024-06-06 16:47:21

...sorry for the multiple posts, I fixed it.

- I had entered "09" as one of the values, instead of just "9", without the zero.

person icon
vp
Guest
Quote
2024-06-07 00:09:30

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.


if (enemy)[6] == "6" //Black Dragon
{
ccbSetCopperCubeVariable("attackscore", 19);
ccbSetCopperCubeVariable("defensescore", 16);
ccbSetCopperCubeVariable("rune", 0);
ccbSetCopperCubeVariable("spell", 0);
ccbSetCopperCubeVariable("item", 0);
};

if (enemy)[7] == "7" //Bronze Argonaut
{
ccbSetCopperCubeVariable("attackscore", 17);
ccbSetCopperCubeVariable("defensescore", 12);
ccbSetCopperCubeVariable("rune", 0);
ccbSetCopperCubeVariable("spell", 0);
ccbSetCopperCubeVariable("item", 0);
};


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.

person icon
Guest
Guest
Quote
2024-06-07 00:21:14

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! emoji icon_smile

person icon
Guest
Guest
Quote
2024-06-07 00:41:45

See here in your example from above:

if (enemy)[155] == "155") //Knight
{
ccbSetCopperCubeVariable("attackscore", 12);
ccbSetCopperCubeVariable("defensescore", 10);
ccbSetCopperCubeVariable("rune", 2);
ccbSetCopperCubeVariable("spell", 155);
ccbSetCopperCubeVariable("item", 155);
};

This should be:

if (enemy[155] == "155") //Knight
{
ccbSetCopperCubeVariable("attackscore", 12);
ccbSetCopperCubeVariable("defensescore", 10);
ccbSetCopperCubeVariable("rune", 2);
ccbSetCopperCubeVariable("spell", 155);
ccbSetCopperCubeVariable("item", 155);
};

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.

person icon
VP
Guest
Quote
2024-06-07 00:53:25

Ahhh, now I see it. Thank you!

person icon
vp
Guest
Quote
2024-06-07 01:17:27

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.

person icon
Guest
Guest
Quote
2024-06-07 18:45:03

You're welcome! Good luck on your project! emoji icon_smile


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 |