Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
text arrays

brian smith
Guest
Quote
2024-11-20 12:55:24

i want to write an array to hold the equipment held by the player. (this is a D&D type game).
how can I set it up in Coppercube and access induvial elements of the list.
Is it possible to write it in JS and access the elements in Coppercube.


okeoke
Registered User
Quote
2024-11-20 13:58:45

You can create an array using js:
var itemsArray = [];

Add any elements
// add number13 to array (for ex. item with id 13)
itemsArray.push(13);

Remove element with index 3
itemsArray.splice(3, 1)

Access individual elements by index. Fx. 0:
 var firstElement = itemsArray[0];

https://developer.mozilla.org/en...


brian
Guest
Quote
2024-11-20 19:13:21

thanks for the info:
I assume this is in JS
I can produce a 2dOverlay box activated by the F1 key,
I want to print elements of the array but cannot seem to get it to work.
I have used the $-$ system to print single values that have been preset and can be altered by overprinting, but I do not know how the print elements of a text array.


okeoke
Registered User
Quote
2024-11-20 19:27:42

It will not work with built-in action. I don't think there is any way to interact with arrays using the built-ins. You also use js to set text like:
var text = '';
for (var i =0; i < array.length; i++) {
text+= array[i] + '\r\n';
}
ccbSetSceneNodeProperty(textNode, 'Text', text);



meh
Guest
Quote
2024-11-20 20:20:05

🔎︎



brian
Guest
Quote
2024-11-20 21:45:54

hi all,
thanks for the info. I will try it out and see it it is suitable.
thanks again


brian
Guest
Quote
2024-11-20 23:19:41

Hi Meh,
thanks for the example. i understand how it would work but (possibly due to my error) when I run the program I get a error message stating ' update Inventory' not defined.
i have checked all the typing and it is exactly the same as your example.
Any ideas?
Brian


meh
Guest
Quote
2024-11-20 23:33:40

check to make sure you don't have spaces in your function definition or function call. it needs to be updateInventory();


meh
Guest
Quote
2024-11-20 23:36:29

and if you can't get it, I can send you an example file or something. just let me know.


meh
Guest
Quote
2024-11-21 00:33:36

went ahead and made an example project with a couple extra bits in it. note: this is just the foundation of an inventory system... lots of ways you can improve and expand upon it.

https://files.catbox.moe/8qur19....


brian
Guest
Quote
2024-11-22 17:37:11

thanks for the help. I THINK i can get the 'player' to hold and use the items in the list
thanks again


meh
Guest
Quote
2024-11-23 03:15:20

well, if you can't do it, just ask and I will help you. here's a hint: look up the term 'callback'... use this with a function called useItem... and the one thing becomes the many...


meh
Guest
Quote
2024-11-23 03:19:49

always remember complexity is evil, simplicity is the good


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inter?ational" (you are not logged in)


Text:

 

  

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


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact