Please fix in file help

Place to get help with not working mods / modding interface.
Airat9000
Smart Inserter
Smart Inserter
Posts: 1418
Joined: Fri Mar 28, 2014 12:32 am
Contact:

Re: Please fix in file help

Post 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
Attachments
2015-11-14_5-59-28.jpg
2015-11-14_5-59-28.jpg (26.94 KiB) Viewed 3644 times
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Please fix in file help

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Airat9000
Smart Inserter
Smart Inserter
Posts: 1418
Joined: Fri Mar 28, 2014 12:32 am
Contact:

Re: Please fix in file help

Post 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
Attachments
GalacticTrade_0.6.9-1.rar
(157.4 KiB) Downloaded 447 times
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Please fix in file help

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Airat9000
Smart Inserter
Smart Inserter
Posts: 1418
Joined: Fri Mar 28, 2014 12:32 am
Contact:

Re: Please fix in file help

Post 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
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Please fix in file help

Post by prg »

Airat9000 wrote:yes
prg wrote:If so, please tell me what to do so I can see the error myself.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Airat9000
Smart Inserter
Smart Inserter
Posts: 1418
Joined: Fri Mar 28, 2014 12:32 am
Contact:

Re: Please fix in file help

Post 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
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Please fix in file help

Post 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?
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Airat9000
Smart Inserter
Smart Inserter
Posts: 1418
Joined: Fri Mar 28, 2014 12:32 am
Contact:

Re: Please fix in file help

Post 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?
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Please fix in file help

Post 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.)
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Airat9000
Smart Inserter
Smart Inserter
Posts: 1418
Joined: Fri Mar 28, 2014 12:32 am
Contact:

Re: Please fix in file help

Post 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.
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Please fix in file help

Post 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?)
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Post Reply

Return to “Modding help”