Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
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. |
||||
|
And the slot names are slot0-slot14 the main overlay is 2DOverlay1 |
||||
|
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. |
||||
|
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. |
||||
|
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 |
||||
|
I left out the “{“ but I do know about it just forgot I just wrote that up |
||||
|
"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." 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. |
||||
|
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. |
||||
|
|