ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator Exe Platform Trouble loading and setting texture
person icon
archangel
Registered User
Quote
2026-03-01 17:34:50

Can some one show me what I am doing wrong here:


/*
<action jsname="action_add_item_to_inventory"
description="Adds an item to the first empty inventory slot">
<property name="ItemNode" type="scenenode" />
<property name="ImageLoad" type="string" default="ArchSigil" />
</action>
*/

action_add_item_to_inventory = function () {
};

action_add_item_to_inventory.prototype.execute = function () {

//Validate inventory overlay
var inventory = ccbGetSceneNodeFromName("inventory");
if (!inventory) {
console.log("Inventory overlay not found.");
return;
}

//Validate item node
if (!this.ItemNode) {
console.log("ItemNode not assigned.");
return;
}

//Get item name
var itemName = ccbGetSceneNodeProperty(this.ItemNode, "Name");
if (!itemName || itemName === "") {
itemName = this.ItemNode.getName ? this.ItemNode.getName() : "UnknownItem";
}

//Get inventory image (Texture1)
var tex = ccbLoadTexture(this.ImageLoad);
if (!tex) {
console.log("ImageSource");
return;
}

console.log("Picking up item:", itemName);

//Loop slots
for (var i = 1; i <= 16; i++) {
var slot = ccbGetSceneNodeFromName("slot" + i);
if (!slot) continue;

var currentImage = ccbGetSceneNodeMaterialProperty(slot, 0, "Texture1");

//Empty slot found
if (!currentImage || currentImage === "") {
try {
ccbSetSceneNodeMaterialProperty(slot, 0, "Texture1", tex);
ccbSetCopperCubeVariable("slot" + i + "_item", itemName);

console.log("Added", itemName, "to slot" + i);
} catch (err) {
console.log("Error setting slot" + i, err);
}
break;
}
}
};



its not working or showing the texture, if there is a better / easier way of doing it let me know. But I need to be able to do it dynamically, not through the editor actions.

person icon
guest
Guest
Quote
2026-03-01 20:11:07

the problem with AI code is you still need to be able to read the code to understand if problems occur. do yourself a favor and learn the basics of JS and read CC's JS API. that said, maybe try copying and pasting the entire JS API documentation into the AI you are using and try again, step by step. first get it to properly print a string to CC's console using print() instead of console.log(). then move onto more advanced stuff. good luck.

person icon
archangel
Registered User
Quote
2026-03-01 21:55:46

A simple response was all that was needed. Trying to talk down on me for using ai for one behavior when everyone uses ai...

And more advanced stuff really... I built the entire VR platform CopperCube will now use for EXE and Webgl... what have you done??? Ill wait...

Im new to the exe platform I used only webgl for years so excuse me if i get some of the calls wrong....

person icon
hadoken
Registered User
Quote
2026-03-01 22:08:59

@archangel, if you give a more detailed description what scene node setup you want to use and what you want to achieve with it in detail, I will try to help.

person icon
archangel
Registered User
Quote
2026-03-01 22:43:28

Thank you @hadoken. But Nevermind Im just going to switch back to using overlays since I got that working on the platform now. I was using plane meshes for the inventory on this one.

But i already know what to do with overlays so im good,

person icon
Guest2
Guest
Quote
2026-04-17 19:08:23

Here is a slightly modified version of the original script, which can serve as a very rough starting point for a limited, minimal "item storage system".
Warning: My experience with JavaScript and CopperCube is also limited and minimal.
I briefly tested the modified script with the Windows target: it seems to "work".

Basic scene layout:
- 1 camera -> Free flying camera
- 4 planes -> representing the 4 default inventory slots: slot1, slot2, slot3, slot4
- 1 cube "my_item" -> example item object -> behavior: "When clicked on this do something" -> executes the "Add an item to ..." action (ItemNode: my_item, ItemImage: testitem.png, SlotCount: 4)

Additional Notes:
- Script filename: "action_add_item_to_inventory.js"
- As suggested by user "guest", calls to "console.log" have been translated into calls to "print"
- The number of default "inventory slots" has been reduced from 16 to 4
- Scheme of CopperCube variables used by the script: "slot1_item", "slot2_item", ..., "slotX_item"


/*
<action jsname="action_add_item_to_inventory" description="Adds an item to the first empty inventory slot">
<property name="ItemNode" type="scenenode" default="" />
<property name="ItemImage" type="string" default="testitem.png" />
<property name="SlotCount" type="int" default="4" />
</action>
*/

action_add_item_to_inventory = function () {
};

action_add_item_to_inventory.prototype.execute = function () {

var itemName = "";

//Check name of ItemNode
var itemName = ccbGetSceneNodeProperty(this.ItemNode, "Name");
if (!itemName || itemName == "") {
itemName = "UnknownItem";
}

print("Picking up item:" + itemName);

//Load item image texture
if (this.ItemImage == "") {
print("ItemImage empty");
return;
} else {
var tex = ccbLoadTexture(this.ItemImage);
if (!tex) {
print("ItemImage " + this.ItemImage + " could not be loaded");
return;
}
}

var item_collected = false;

//Check the "inventory" for free slots
for (var i = 1; i <= this.SlotCount; i++) {
var slot = ccbGetSceneNodeFromName("slot" + i);
if (!slot) continue;

//Check if this slot is occupied
if (ccbGetCopperCubeVariable("slot" + i + "_item") == "") {
ccbSetSceneNodeMaterialProperty(slot, 0, "Texture1", tex); //slot texture = ItemImage texture
ccbSetCopperCubeVariable("slot" + i + "_item", itemName);

print("Added " + itemName + " to slot" + i);
item_collected = true; //mark item as collected
break;
}
}

//If the item could not be collected, report that the inventory is full
if (item_collected == false) {
print("Inventory - no free slots");
return;
}
};



Parameters of the action:
- "ItemNode" = scene node, game-world object that represents the item to be added to the inventory
- "ItemImage" = relative path to a texture file; will be displayed on the "inventory slot" plane
- "SlotCount" = number of "inventory slots"

IMPORTANT: The filename in ItemImage must point to a valid texture file in the project / game directory (relative path). Example path: "imagedir\\testitem.png"

- If you want to add more "inventory slots", adjust the SlotCount-parameter and place additional plane objects with appropriate names ("slot5", "slot6", "slot7", etc.)

Ideas for further d

person icon
Guest2
Guest
Quote
2026-04-17 19:12:29

Continuation of the previous post:

Ideas for further development:
- After adding the item to the inventory, "deactivate" the item-object in the game world
- Add a label (2D overlay) to the item slots that displays the name of the currently selected item
- Add actions for specific events that can be triggered by the script: Inventory full, Item picked up / not picked up
- Add a function to select specific inventory slots and trigger item-usage
- Add a function to drop items from selected slots
- And so on...

Thanks to the original author/publisher who made this script available.

If there are any major errors in the modified script or in my descriptions, I would appreciate it if more experienced users would point them out.


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 |