ID:587169
 
(See the best response by Robertbanks2.)
Code: Test code
mob/proc
ImproveWeap()
var/list/itemPack = list()
for(var/obj/Items/Equipment/F in src.Inventory)
itemPack = list(F)
var/E = input(src,"What equipment do you wish to fortify ?","Choose:") as null|anything in itemPack+"Cancel"
if(E == "Cancel") return
else
if(F.plusF == 0)
if(src.exampleOne >= 1 && src.exampleTwo >= 3 && src.actualCurrency >= 500)
src.exampleOne -= 1;src.exampleTwo -= 3;src.actualCurrency -= 500
F.statOne *= 0.10
F.statTwo *= 0.10
F.plusF = 1
src << "You succesfully improved your equipment!"
else
src << "You don't meet the requirements!"
return


Problem description: My problem is, it only shows one object at time, shouldn't it show all the objects I have in inventory in that list ? This is probably a very easy fix, but I don't see how I can manage it, I tried all I know, unless something in that code is wrong. Thanks in advance. PS: Code is only half done, just want to know why that happens.

Best response
No, because you're looping through the whole thing for each object. You need to add the items to the list individually, THEN use input(). Basically you want to un-indent everything after itemPack = list(F) by one.

Also, itemPack = list(F) sets the list to a single object every time, you need itemPack += F or the Add() proc. It's already defined as a list, so you don't need to change from a list to a list.
itemPack.Add(F)

Well I had that before what I have now, it'll add every object I have in inventory one by one whenver I click OK. Also I don't understand what do you mean with that first part.
Assuming you worded your problem correctly, and I'm reading it correctly, the issue is that you're putting up the input for each individual object, not the entire list.

To do this, you have to loop through the objects in your inventory, and add the ones you want to your list. Then, outside of the loop, you use the full list in the input() to see what you want to upgrade.

If the input() is INSIDE the for() loop that you're using to add the items to the list that you're trying to use inside the input(), it won't work, for obvious reasons.
Hope I am understand what you are saying, the reason I put input inside of the loop is to recognize J as the equip, otherwise I think it would make errors, like don't recognize J.statOne...
The problem is that your code does this in human language
for each Equipment item
make a list containing only that item
allow the player to chose one item from that list+cancel
do whatever on that item

while what you want to do is create a list containing all equipment items then allow the player to choose one of them, which would require something like this

mob/proc
ImproveWeap()
var/list/itemPack = list()
for(var/obj/Items/Equipment/F in src.Inventory)
itemPack += F
var/E = input(src,"What equipment do you wish to fortify ?","Choose:") as null|anything in itemPack+"Cancel"
if(E != "Cancel")
if(F.plusF == 0)
if(src.exampleOne >= 1 && src.exampleTwo >= 3 && src.actualCurrency >= 500)
src.exampleOne -= 1;src.exampleTwo -= 3;src.actualCurrency -= 500
F.statOne *= 0.10
F.statTwo *= 0.10
F.plusF = 1
src << "You succesfully improved your equipment!"
else
src << "You don't meet the requirements!"
Like I was trying to say, if I do something like that, this will appear -> F.plusF: undefined var .

That's why I was running input() under for(), to recognize F as the object.
Ah... right... I didn't even notice. All those F. after the input should be E. instead. They must refer to the item you actually chose.
Something tells me that won't work either, I just don't know what's going on.. What am I missing in that bloody code, I've tried several things.
You have to typecast E properly.

var/obj/equipzorz/blabla/E = input()
Well I tried var/obj/E before, didn't work.. Now I tried var/obj/Items/Equipments/E = input() and nothing, so yeah thanks for all the help. I think I'll just quit this bloody code. :|
Could you post the final version of your code instead? It's a pity to quit. :-)
Well this is the las thing I tried..
mob/proc
ImproveWeap()
var/list/itemPack = list()
for(var/obj/Items/Equipment/F in src.Inventory)
itemPack = list(F)
var/obj/Items/Equipments/E = input(src,"What equipment do you wish to fortify ?","Choose:") as null|anything in itemPack+"Cancel"
if(E != "Cancel")
if(F.plusF == 0)
if(src.exampleOne >= 1 && src.exampleTwo >= 3 && src.actualCurrency >= 500)
src.exampleOne -= 1;src.exampleTwo -= 3;src.actualCurrency -= 500
F.statOne *= 0.10
F.statTwo *= 0.10
F.plusF = 1
src << "You succesfully improved your equipment!"
else
src << "You don't meet the requirements!"
return


Am I doing anything wrong, is it how I did E ?
In response to YasuShy
YasuShy wrote:
>       var/list/itemPack = list()
> for(var/obj/Items/Equipment/F in src.Inventory)
> itemPack = list(F)
>


For each /obj/Items/Equipment in your inventory, this loop is creating a new list from scratch and placing the current item (F) in it. Instead, you need to be adding the current item (F) to the existing list with itemPack.Add(F).

>       var/obj/Items/Equipment/E = input(src,"What equipment do you wish to fortify ?","Choose:") as null|anything in itemPack+"Cancel"
> if(E != "Cancel")
>


Using the as null|anything setting automatically adds an actual "cancel" button to the input dialog box, so you don't need to add one to the option list. If the player presses the actual cancel button, the input() will return null. To handle this, you could change the following if() statement to simply if(E).

>           if(F.plusF == 0)
> if(src.exampleOne >= 1 && src.exampleTwo >= 3 && src.actualCurrency >= 500)
> src.exampleOne -= 1;src.exampleTwo -= 3;src.actualCurrency -= 500
> F.statOne *= 0.10
> F.statTwo *= 0.10
> F.plusF = 1
> src << "You succesfully improved your equipment!"
> else
> src << "You don't meet the requirements!"
> return
>

Am I doing anything wrong, is it how I did E ?

You aren't using E! ;)

The variable E holds the piece of equipment that the user selected, not F (which is actually out of scope by this point, as F only exists within the for() loop). So replace those instances of F with E.

You did at least 3 things wrong as far as I can say:

mob/proc
ImproveWeap()
var/list/itemPack = list()
for(var/obj/Items/Equipment/F in src.Inventory)
itemPack += F // NOT itemPack = list(F)
var/obj/Items/Equipment/E = input(src,"What equipment do you wish to fortify ?","Choose:") as null|anything in itemPack+"Cancel" // you wrote "EquipmentS" in your code
if(E != "Cancel")
// from here on all F must be E instead, so:
if(E.plusF == 0)
if(src.exampleOne >= 1 && src.exampleTwo >= 3 && src.actualCurrency >= 500)
src.exampleOne -= 1;src.exampleTwo -= 3;src.actualCurrency -= 500
E.statOne *= 0.10
E.statTwo *= 0.10
E.plusF = 1
src << "You succesfully improved your equipment!"
else
src << "You don't meet the requirements!"
Thanks for all the people who helped me here, I am starting to understand better what we did here. My problem was EquipmentS, it need to be Equipment that's why it was giving me some path error. Also now all the equipment in inventory is showing. Thank you.