Code:
Problem description:
right now if i buy an item its one by one, i need to add an input thing to buy multiple items, i just am not sure how. and after that i need specific items to stack and specific ones not to, how do i edit the specific items properties to be stackable? i have some code put in for item stacking but the items still dont do it, i see something saying -1 means unstackable and 1+ means stackable and 0 means delete or something like that but i dont know how to change the items to be recognized as that.
I'll get you the run down of how it's generally done.
1. Extra "amount" variable on object 2. When you pick something new up, add it to your inventory 3. If you already have an instance in your inventory, add amount to that instance and delete the object on the ground. It's not super-advanced code, mostly loops through your inventory. obj |
In response to Lugia319
|
|
var/obj/Old = locate(src.type) in usr I'm not quite sure which method (yours or mine) would be the more efficient of the two. I will test this now and post back with the results. I'm just going to look at the world profiler. |
In response to Spunky_Girl
|
|
I have some results. I made two different procs to separate the two methods and then made two loops that creates a new obj instance and calls one of the two procs to add it to the contents on each iteration. Each loop did this 1,000 times.
The results were that the method I posted used up about 480% more CPU than the other. Would someone mind explaining to me why that is? How come locate() eats more than a for() loop in terms of the CPU? |
In response to Spunky_Girl
|
|
Can you show us the exact code you used when profiling (for both methods)?
Did you remember to add the call to Move() to Lugia319's version? And did you put anything in the player's contents? |
mob I just now tested it with the commented out updateInventory() procs and now the results make sense to me. After 1,000 calls to each one, addItem2() used 0.001 less than addItem(). |
im wanting items like a potion to stack, but items like equipment not too. can we make something to make it known if it should be stacked
|
i tried to do that but it wasnt working, im sure i just didnt put it right , i tried making them -1 and 1+
|
http://www.byond.com/developer/Buzzyboy/ItemStacking