tag:blogger.com,1999:blog-4740038019232623478.post321304867676807048..comments2023-10-31T07:51:27.779-07:00Comments on Daisy_Strike's SDK: Back to the testerDaisy_Strikehttp://www.blogger.com/profile/04943903869046211819noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-4740038019232623478.post-82572905882221977122011-06-01T15:29:49.909-07:002011-06-01T15:29:49.909-07:00Ah, apologies, I see what you're saying - rath...Ah, apologies, I see what you're saying - rather than push() and pop() to manage inventory items you'll need to adjust a property of the class.<br /><br />The best way to handle this is to have two arrays, one associative and one not.<br />So what you can do is the following:<br /><br />Inventory is an array of strings, and the strings are keys to the Items associative array. If the item doesn't already exist, you can create it with the new objects.<br /><br />for example:<br /><br />// I'm assuming that StackableObject has methods<br />// quantity() that gives the value of an <br />// internal quantity property, add()<br />// that adds a number to the quantity property,<br />// name() that returns the name property,<br />// and a constructor that takes a string for <br />// name and an integer for quantity.<br /><br />m = new StackableObject("Milk", 3);<br /><br />Items = new Array();<br />Items[m.name()] = m;<br /><br />Inventory = new Array();<br />Inventory.push("Milk");<br /><br />trace(Items["Milk"].quantity()); // 3<br /><br />// So you've put a string in the inventory<br />// If you produce another milk you can just<br />// do the following assuming there's an add()<br />// method in the StackableObject class.<br /><br />Items["Milk"].add(1);<br />trace(Items["Milk"].quantity()); // 4<br /><br />Removing items from the inventory is more complex because delete doesn't change the length of the array, you just have an empty item - pop() removes the complexity so it's easier but as you noted, it's doesn't work as handily when your item can be anywhere in the array.<br /><br />For this, I'd suggest looking at this thread which discusses extending the array object by adding an indexOf method that allows for searching by value. http://www.kirupa.com/forum/showthread.php?190234-Finding-Any-Value-in-Array-%28not-indexOf%29<br /><br />Then you can use Array.splice to remove items entirely.Neriohttp://no.website.ienoreply@blogger.comtag:blogger.com,1999:blog-4740038019232623478.post-36234076276568657292011-05-31T18:36:01.107-07:002011-05-31T18:36:01.107-07:00Couldn't you just update the Item class to inc...Couldn't you just update the Item class to include that extra information? (After all, maybe the store's selling a 3-pack of healing potions, or you might find a couple apples on the ground, so it could be useful, even for items outside of the inventory.)<br /><br />Then you could use something like:<br />var temp:Item = new Item(itemName, producerName, quantity);<br /><br />itemArray.push(temp);<br /><br />So, rather than an array of strings, you get an array of items.<br /><br />Of course, you'll need to check to see if an item with that name already exists. If so, add the new item's quantity to the old one's. If not, push the new item. That's going to be a problem, no matter how you implement it, though.<br /><br />If you don't need to provide all of those values for every item in the game,just provide some default values, so maybe the constructor might look something like this:<br />public Item(itemName:String, itemProducer:String = "unknown", itemQuantity:int = 1)<br />{<br /> name=itemName;<br /> producer=itemProducer;<br /> quantity=itemQuantity;<br />}compuscribenoreply@blogger.comtag:blogger.com,1999:blog-4740038019232623478.post-19396706682832147162011-05-31T15:12:15.068-07:002011-05-31T15:12:15.068-07:00I think your missing the point I can definitely ad...I think your missing the point I can definitely add an object, that's what I'm doing. But it has to go through a constructor.<br /><br />it was:<br /><br />itemArray.push("item_name");<br /><br />but now i have to define the items of the object unless i want to make a new type of class for every item... <br /><br />public static function createNewItem(item_name:String, producer:String, number:int, tempArr:Array) {<br />var temp:Item = new Item();<br />temp.name = item_name;<br />temp.producer = producer;<br />if (number <= 0) {<br />temp.number = 1;<br />}<br />else {<br />temp.number = number;<br />}<br />tempArr.push(temp);<br />}<br /><br />DaisyDaisy_Strikehttps://www.blogger.com/profile/04943903869046211819noreply@blogger.comtag:blogger.com,1999:blog-4740038019232623478.post-61272524679609519082011-05-31T11:25:11.432-07:002011-05-31T11:25:11.432-07:00I'm not sure where your problem is.
Flash arr...I'm not sure where your problem is.<br /><br />Flash arrays can contain elements of any type any type, so you can do:<br />Array.push(new StackableObject);<br />and then Array.pop() will give you back the last StackableObject in the array. <br /><br />If all the objects are the same you can use a vector rather than an array - vectors can only contain one type, but as long as your vector will have only one type of StackableObject (i.e. Milk) then that's not a problem. push() and pop() will work as expected. So you'd have<br />var MilkVector:Vector.;<br />MilkVector = new Vector.();<br /><br />MilkVector.push() and MilkVector.pop() then give you the behaviour you want.Neriohttp://no.website.ienoreply@blogger.comtag:blogger.com,1999:blog-4740038019232623478.post-27525208410371659092011-05-31T02:30:43.564-07:002011-05-31T02:30:43.564-07:00Hm i wonder what's the remaining feature left ...Hm i wonder what's the remaining feature left to be implement? Is it still much? Hope someone compile it into one release and it's not too long.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4740038019232623478.post-91597986211910448322011-05-30T21:49:14.186-07:002011-05-30T21:49:14.186-07:00when is the next download going to be available?
t...when is the next download going to be available?<br />tyAnonymousnoreply@blogger.com