ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator Inventory
person icon
Noobski
Guest
Quote
2024-02-10 21:50:27

I have a 2d overlay comprised of 15 smaller overlays acting as inventory slots. I have a code in place that will add the items to my inventory and when I click on them it removes the image as if it were used. Now I need a behavior that would when clicked on the slot it would check for the image that is attached and based of that image since the items have the same exact name minus the .ext png, it would do a certain action after. In example I added a health potion to my inventory, and the image is pot.png I need to to recognize that image and perform a certain action based off of the item “pot” like give the player +25 health. And with a weapon I hide the weapon in his hand if the item was a sword or bow or staff. For me it’s not as easy as choosing the unhide scene node because if he has more that one weapon hidden in the same hand it injured them all for me so idk what to do. If I can get this inventory part handled I could definitely get the ball rolling on my game. Thank you for reading and any future help provided.

person icon
Noobski
Guest
Quote
2024-02-10 22:19:25

And the slot names are slot0-slot14 the main overlay is 2DOverlay1

person icon
Guest
Guest
Quote
2024-02-11 01:39:42

There's many different ways to go about what you ask. If you want help then post an example project with your code so we can see what you are doing. Guessing at how you have set up everything is a waste of time. Also please don't ask for help in other parts of the forum when posting your question here is enough.

person icon
Noobski
Guest
Quote
2024-02-11 01:52:36

I mean I literally explained it in good detail for someone to know how to put the code together if they are good at programming in coppercube. I have the names of the slots and the main slot name and the items and that they are the same name as the images that will appear in the slot mins that the slots image has a .png/ example item is “bow” and image is bow.png. I explained in great detail what I want to do. And that the weapons slot is child node of player and even gave the player nodes name “player” all the detail to know not “guess” at what I’m trying to do. I’m on my phone but when I get to my computer I guess I can post the code of how it adds to the inv and how it removes it but that has nothing to do with the script I need. I don’t have one written for this anymore because none of them worked so I need someone with knowledge to understand what I’m asking. But thank you for your response though however helpful it was. Not trying to be rude.

person icon
Noobski
Guest
Quote
2024-02-11 02:16:11

Guess it would be something like so:

Var slotNode = “slot0”;
Var slotName = slotNode;
Var currentImage = ccbGetSceneNodeProperty(slotName, “image”);

If(currentImage)
If(currentImage === “pot.png”);
CcbSetCopperCubeVariable(“” + “player.health”);

And plus 25 or whatever because everything I try doesn’t work

person icon
Noobski
Guest
Quote
2024-02-11 02:18:27

I left out the “{“ but I do know about it just forgot I just wrote that up

person icon
Guest
Guest
Quote
2024-02-11 03:13:08

"Now I need a behavior that would when clicked on the slot it would check for the image that is attached and based of that image since the items have the same exact name minus the .ext png, it would do a certain action after."

embedded external image
🔎︎


Use this code as an example of how to get the image name and do something based on the result. No clue what else you want from your post.

person icon
okeoke
Registered User
Quote
2024-02-11 06:32:53

https://zeicmann.itch.io/ccb-var... Example of almost what you ask here.

If I remember correctly I'm using indexes. Every 2d overlay node has on hover action attached which changes global variable value to its index. In case player left clicks and this variable is not null, it accesses inventory array element by the clicked overlay's index. You can do pretty much the same with overlay node names.

In order to produce an action like "add 25 hp", each item that could be added to the inventory, has its own "onUse" function.


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 |