Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
so as a start "okeoke" do you think this script will or will not work and if anything is wrong and if you can correct it please thanks. im getting this errior when running it : SyntaxError: missing ) after argument list code: /* <action jsname="action_InventoryClick" description="Inventory Click"> <property name="SlotIndex" type=int" default="0" /> <property name="ExternalHealthVariable" type="string" default="" /> <property name="AnyAction" type="action" default="" /> <property name="AnyAction1" type="action" default="" /> <property name="AnyAction2" type="action" default="" /> <property name="AnyAction3" type="action" default="" /> </action> */ action_InventoryClick = function() { }; action_InventoryClick.prototype.execute = function(currentNode) { var slotIndex = this.SlotIndex; var slotName = "slot" + slotIndex; var slotImage = ccbGetSceneNodeProperty(2DOverlay1[slotName], "Image"); //Check the item in slot if (slotImage == "bow.png") { this.handleBowAction(); } else if (slotImage == "pot.png") { this.handlePotAction(); } else if (slotImage == "sword.png") { this.handleSwordAction(); } else if (slotImage == "mace.png") { this.handleMaceAction(); } else { this.handleUnknownItemAction(); } }; action_InventoryClick.prototype.handlePotAction = function() { //execute pot action var healthIncrease = 25; if (this.ExternalHealthVariable !== "") { var currentHealth = ccbGetCopperCubeVariable(this.ExternalHealthVariable); ccbSetCopperCubeVariable(this.ExternalHealthVariable, currentHealth + healthIncrease); print("Player health increased by 25!"); } else { print("ExternalHealthVariable is not set. Cannot increase player health."); } }; action_InventoryClick.prototype.handleBowAction = function() { // Execute bow (this.AnyAction); print("Bow equipped"); }; action_InventoryClick.prototype.handleSwordAction = function() { // Execute sword (this.AnyAction1); print("Sword equipped"); }; action_InventoryClick.prototype.handleMaceAction = function() { // Execute mace (this.AnyAction2); print("Mace equipped"); }; action_InventoryClick.prototype.handleUnknownItemAction = function() { // Execute unknown item action (this.AnyAction3); print("Unknown item. No action defined"); }; |
||||
|
Hi "Noobski", no it will not. You can not use variables which start with a numeric literal like 2dOverlay, which I believe I mentioned to you before. Also you're not calling actions properly - refer to api, you need to use ccbInvokeAction for that. I'm not sure if this is even a valid syntax: (this.AnyAction); |
||||
|
Alright so I know about the 2DOverlay yes I just kept getting errors and was trying other ways but I thought you said I could do it like so ([“2Doverlay1”]) if not I’ll change the name completely to Inventory. And if I fix the ccbInvokeAction for the others you think the rest of the code looks good? Like everything should work once I make those fixes? This was just I rough draft so you could see what I’m trying to do and correct me and point me in the right direction. And thank you for all your advice! |
||||
|
And for the “AnyAction setup” I have it like so so I can just use the “unhide scene node” action in coppercube to directly I hide the weapon in the players weapon slot child node, since I haven’t figured out a way to do that through code yet but I actually like and prefer the way I’m setting it up to do it like that long as I can get it right. |
||||
|
The Image property will never be "bow.png" because it returns a path. You need more code to handle that situation. |
||||
|
|