Page 2 of 2

Re: Please fix in file help

Posted: Sat Nov 14, 2015 2:59 am
by Airat9000
prg wrote:The original code was

Code: Select all

max_buy_amount = (slots_available * script.item_prototypes[global.buyingtradingchests.item_selected[i]].stack_size) - item_count
You replaced that with

Code: Select all

max_buy_amount = (slots_available * game.item_prototypes[global.buyingtradingchests.item_selected[item_selected]].stack_size) - item_count
right? There are two changes, only one of which seems to make sense to me.
not effect bug

Re: Please fix in file help

Posted: Sat Nov 14, 2015 10:51 pm
by prg
Alright, I can't tell just by reading that snippet of code what's going on. If you provide the current version of the code and steps to reproduce, I can take a closer look.

Re: Please fix in file help

Posted: Sun Nov 15, 2015 1:57 am
by Airat9000
prg wrote:Alright, I can't tell just by reading that snippet of code what's going on. If you provide the current version of the code and steps to reproduce, I can take a closer look.
files

Re: Please fix in file help

Posted: Sun Nov 15, 2015 9:29 am
by prg
Okay, since you didn't provide steps to reproduce, just randomly clicking buttons in a newly started game doesn't trigger the error and I haven't untangled things far enough to figure out when this piece of code is supposed to run I only had a look at it without actually trying it myself, and... it still says item_selected[item_selected]. You did try that with item_selected like it used to be, right? If so, please tell me what to do so I can see the error myself.

Re: Please fix in file help

Posted: Mon Nov 16, 2015 4:19 am
by Airat9000
prg wrote:Okay, since you didn't provide steps to reproduce, just randomly clicking buttons in a newly started game doesn't trigger the error and I haven't untangled things far enough to figure out when this piece of code is supposed to run I only had a look at it without actually trying it myself, and... it still says item_selected[item_selected]. You did try that with item_selected like it used to be, right? If so, please tell me what to do so I can see the error myself.

yes

Re: Please fix in file help

Posted: Mon Nov 16, 2015 9:34 am
by prg
Airat9000 wrote:yes
prg wrote:If so, please tell me what to do so I can see the error myself.

Re: Please fix in file help

Posted: Tue Nov 17, 2015 9:18 am
by Airat9000
prg wrote:
Airat9000 wrote:yes
prg wrote:If so, please tell me what to do so I can see the error myself.
try to correct the file
i am file in add to old

Re: Please fix in file help

Posted: Tue Nov 17, 2015 11:54 am
by prg
Airat9000 wrote:try to correct the file
i am file in add to old
It appears there might be some difficulties with understanding each other. What I had been looking for was a sequence of steps so I could reproduce the issue myself, like
  • Start a new game with the mod enabled
  • /c game.player.insert{name="logistic-trading-chest-buy"}
  • Plop down the chest
  • Open the chest
  • In the resulting "Choose an item" dialog click a random item
  • Enter some number in the left "Selected item" dialog
  • Click the "GT" button in the top left corner
This indeed results in "Error while running the event handler: __GalacticTrade__/control.lua:1031: attempt to index field '?' (a nil value)" which, contrary to your claims, is fixed for me by changing item_selected[item_selected] in that line back to the original code's version of item_selected, like I've been trying to suggest for a while now.

Just to make sure, in control.lua, line 1031, change

Code: Select all

max_buy_amount = (slots_available * game.item_prototypes[global.buyingtradingchests.item_selected[item_selected]].stack_size) - item_count
to

Code: Select all

max_buy_amount = (slots_available * game.item_prototypes[global.buyingtradingchests.item_selected[i]].stack_size) - item_count
You're still claiming this doesn't make a difference for you? What is the reason you made that change in the first place? Can you provide steps to reproduce the issue with the changed code?

Re: Please fix in file help

Posted: Tue Nov 17, 2015 2:23 pm
by Airat9000
prg wrote:
Airat9000 wrote:try to correct the file
i am file in add to old
It appears there might be some difficulties with understanding each other. What I had been looking for was a sequence of steps so I could reproduce the issue myself, like
  • Start a new game with the mod enabled
  • /c game.player.insert{name="logistic-trading-chest-buy"}
  • Plop down the chest
  • Open the chest
  • In the resulting "Choose an item" dialog click a random item
  • Enter some number in the left "Selected item" dialog
  • Click the "GT" button in the top left corner
This indeed results in "Error while running the event handler: __GalacticTrade__/control.lua:1031: attempt to index field '?' (a nil value)" which, contrary to your claims, is fixed for me by changing item_selected[item_selected] in that line back to the original code's version of item_selected, like I've been trying to suggest for a while now.

Just to make sure, in control.lua, line 1031, change

Code: Select all

max_buy_amount = (slots_available * game.item_prototypes[global.buyingtradingchests.item_selected[item_selected]].stack_size) - item_count
to

Code: Select all

max_buy_amount = (slots_available * game.item_prototypes[global.buyingtradingchests.item_selected[i]].stack_size) - item_count
You're still claiming this doesn't make a difference for you? What is the reason you made that change in the first place? Can you provide steps to reproduce the issue with the changed code?

understood you. You can view the file as was the change?

Re: Please fix in file help

Posted: Tue Nov 17, 2015 5:44 pm
by prg
Airat9000 wrote:understood you. You can view the file as was the change?
I'm sorry, I don't quite understand you. How I was able to view differences between files? There's this handy "diff" utility.

Code: Select all

$ diff -bru GalacticTrade_0.6.[59]/
[...]
@@ -1028,7 +1028,7 @@
                                        end
 
                                        if slots_available>0 then
-                                               max_buy_amount = (slots_available * script.item_prototypes[global.buyingtradingchests.item_selected[i]].stack_size) - item_count
+                                               max_buy_amount = (slots_available * game.item_prototypes[global.buyingtradingchests.item_selected[item_selected]].stack_size) - item_count
                                                if item_difference > max_buy_amount then
                                                        item_difference = max_buy_amount
                                                end
[...]
This also shows another suspicious change on line 553:

Code: Select all

@@ -550,14 +550,14 @@
                        for name, amount in pairs(contents) do
                                global.buyingtradingchests.chest[chest_index].get_inventory(1).insert({name = name, count = amount})
                                if name ~= global.buyingtradingchests.item_selected[chest_index] then
-                                       slots_available = slots_available - math.ceil(amount/script.item_prototypes[global.buyingtradingchests.item_selected[chest_index]].stack_size)                                                                                                    
+                                       slots_available = slots_available - math.ceil(amount/game.item_prototypes[global.buyingtradingchests.item_selected[item_index]].localised_name.stack_size)                                                                                        
                                end
                        end
You changed chest_index into item_index which isn't defined anywhere in that function and added a .localised_name in front of the .stack_size which totally doesn't make sense. (And the whole thing is inside an "if chest == chest" which doesn't appear to be terribly useful to me, but seems like it was that way already in the original.)

Also, you've still missed a few get_localised_item_name calls.

Code: Select all

$ grep -n get_localised -r GalacticTrade_0.6.9/
GalacticTrade_0.6.9/prototypes/control.lua:794:                                         p.gui.left.tradingchest_buy.item_view_table.add{type="label",name="item_label",caption=game.get_localised_item_name(global.buyingtradingchests.item_selected[item_index])}
GalacticTrade_0.6.9/prototypes/scripts/trading-chest.lua:350:                           p.gui.left.tradingchest_buy.item_view_table.item_label.caption = game.get_localised_item_name(global.buyingtradingchests.item_selected[chest_index])
GalacticTrade_0.6.9/prototypes/prototypes/scripts/trading-chest.lua:350:                                p.gui.left.tradingchest_buy.item_view_table.item_label.caption = game.get_localised_item_name(global.buyingtradingchests.item_selected[chest_index])
GalacticTrade_0.6.9/prototypes/prototypes/scripts/trading-chest.lua:397:                                p.gui.left.tradingchest_buy.item_view_table.item_label.caption = game.get_localised_item_name(item.name)
(Why are there scripts containing game logic inside the prototypes/ directory? And then again inside prototypes/prototypes/? I'm a bit scared of that code I need to admit.)

Re: Please fix in file help

Posted: Wed Nov 18, 2015 8:10 am
by Airat9000
prg wrote:
Airat9000 wrote:understood you. You can view the file as was the change?
I'm sorry, I don't quite understand you. How I was able to view differences between files? There's this handy "diff" utility.

Code: Select all

$ diff -bru GalacticTrade_0.6.[59]/
[...]
@@ -1028,7 +1028,7 @@
                                        end
 
                                        if slots_available>0 then
-                                               max_buy_amount = (slots_available * script.item_prototypes[global.buyingtradingchests.item_selected[i]].stack_size) - item_count
+                                               max_buy_amount = (slots_available * game.item_prototypes[global.buyingtradingchests.item_selected[item_selected]].stack_size) - item_count
                                                if item_difference > max_buy_amount then
                                                        item_difference = max_buy_amount
                                                end
[...]
This also shows another suspicious change on line 553:

Code: Select all

@@ -550,14 +550,14 @@
                        for name, amount in pairs(contents) do
                                global.buyingtradingchests.chest[chest_index].get_inventory(1).insert({name = name, count = amount})
                                if name ~= global.buyingtradingchests.item_selected[chest_index] then
-                                       slots_available = slots_available - math.ceil(amount/script.item_prototypes[global.buyingtradingchests.item_selected[chest_index]].stack_size)                                                                                                    
+                                       slots_available = slots_available - math.ceil(amount/game.item_prototypes[global.buyingtradingchests.item_selected[item_index]].localised_name.stack_size)                                                                                        
                                end
                        end
You changed chest_index into item_index which isn't defined anywhere in that function and added a .localised_name in front of the .stack_size which totally doesn't make sense. (And the whole thing is inside an "if chest == chest" which doesn't appear to be terribly useful to me, but seems like it was that way already in the original.)

Also, you've still missed a few get_localised_item_name calls.

Code: Select all

$ grep -n get_localised -r GalacticTrade_0.6.9/
GalacticTrade_0.6.9/prototypes/control.lua:794:                                         p.gui.left.tradingchest_buy.item_view_table.add{type="label",name="item_label",caption=game.get_localised_item_name(global.buyingtradingchests.item_selected[item_index])}
GalacticTrade_0.6.9/prototypes/scripts/trading-chest.lua:350:                           p.gui.left.tradingchest_buy.item_view_table.item_label.caption = game.get_localised_item_name(global.buyingtradingchests.item_selected[chest_index])
GalacticTrade_0.6.9/prototypes/prototypes/scripts/trading-chest.lua:350:                                p.gui.left.tradingchest_buy.item_view_table.item_label.caption = game.get_localised_item_name(global.buyingtradingchests.item_selected[chest_index])
GalacticTrade_0.6.9/prototypes/prototypes/scripts/trading-chest.lua:397:                                p.gui.left.tradingchest_buy.item_view_table.item_label.caption = game.get_localised_item_name(item.name)
(Why are there scripts containing game logic inside the prototypes/ directory? And then again inside prototypes/prototypes/? I'm a bit scared of that code I need to admit.)
the script makes recalculation of price again not to start the game again, simply restart the file already started
others form a message of those things that can not be sold.

Re: Please fix in file help

Posted: Wed Nov 18, 2015 11:46 am
by prg
Airat9000 wrote:the script makes recalculation of price again not to start the game again, simply restart the file already started
others form a message of those things that can not be sold.
Again I'm not sure what you're trying to say here. Yes, the mod precalculates some values at the beginning for some reason and there's a button to recalculate them in a running game. Not sure how that's relevant to the things I pointed out. The issues mentioned do cause breakage, try buying two different things with the same buying chest or try copy/pasting with the buttons in the "Selected item" dialog.

Also the organisation of the files does not make sense, a script does not need to be placed in prototypes/ to be able to access game.item_prototypes (or what was the reasoning here?)