Page 1 of 1

[0.12.8] can_insert always gives false.

Posted: Wed Sep 30, 2015 7:16 pm
by matjojo
EDIT: please read the second page from top, the first on on the second page explains my mistake

whilst working on EE2 I tried checking if there was space in the player's inventory. I did this this way:

Code: Select all

if game.player.can_insert{name = game.player.gui.left.EE_energy_condenser.EE_flow_item_selector.EE_label_item_selector.caption, count = 1} == true then
The caption is an always assigned item ID and well, the count is always 1.
I Always seem to get a return that was not true, these are the tested cases:

* player has space in main inventory and belt.
* player has space in main inventory but not in belt.
* player does not have space in main inventory but does have space in belt.
* player does not have space in main inventory and not in belt.

all the cases did not result in can_insert actually returning true. attached are the save and the mod files.

instructions to create a scenario in which the inv is not full and the command thinks it is.
1: give yourself an Energy condenser either with test mode (the pic is a wooden chest for now) or with the command(item name= energy-condenser)
2: grab two different items from somewhere, It can be every item
3: open the Energy condenser and click the "select item" button with an item of choice in hand.
4: grab the other item in your hand
5: press the button with this item in hand
6: see as the game prints the message "the player inventory seems to be full" (I made the mod give this message as the inv was full to check this bug's existence)
7: AFTER THIS THE GAME MIGHT CRASH DUE TO EE2 THIS IS JUST A PROBLEM IN THE MOD AND IS NOT ASSOCIATED WITH THIS BUG-REPORT
8: see as the game actually should not have detected a full inventory.

instructions for creating a scenario in which the command seems to work.
1: give yourself an Energy condenser either with test mode (the pic is a wooden chest for now) or with the command(item name= energy-condenser)
2: grab two different items from somewhere, It can be every item
3: open the Energy condenser and click the "select item" button with an item of choice in hand.
4: do this command: "/c game.player.cursor_stack.set_stack{name = "iron-plate", count= "5000000"}" (make sure to do this inside of the energy condenser)
5: place this stack in the Energy condenser inventory.
6: ctrl click this stack to fill the whole player inventory.
7: manually fill the whole player-belt. (clicking the 5mil stack will give you a full stack)
8: press the select item button with another item as that you have currently selected it with. (make sure to fill the spot it had in the player's inventory/belt (if you had it there))
9: see as the game prints the message "the player inventory seems to be full" (I made the mod give this message as the inv was full to check this bug's existence)
10: AFTER THIS THE GAME MIGHT CRASH DUE TO EE2 THIS IS JUST A PROBLEM IN THE MOD AND IS NOT ASSOCIATED WITH THIS BUG-REPORT
11: see as this worked, the inv was full and the command detected this.

other instructions you can probably think of yourself.
Laptop specs:
CPU: Intel Core i3-4005U 1.7GHZ
IGPU: Intel HD 4400
Motherboard: Unknown Laptop Motherboard
Disclaimer: I do have a second screen attached, it is attached thru HDMI. (unknown type)

I hope this post gave enough information. As always I'll gladly give omr information of necessary.

Re: [0.12.8] can_insert always gives false.

Posted: Thu Oct 01, 2015 6:58 am
by Rseding91
GuiElement::caption returns a localized string. Are you setting the button.caption to a literal string: "iron-ore" or the localized string name of iron-ore?

Re: [0.12.8] can_insert always gives false.

Posted: Thu Oct 01, 2015 10:03 am
by matjojo
Rseding91 wrote:GuiElement::caption returns a localized string. Are you setting the button.caption to a literal string: "iron-ore" or the localized string name of iron-ore?

currently I have it set to display the literal string, not the localised. is this wrong?

I mean should I insert the Localised string to can_insert? not if it's wrong on the button.

Re: [0.12.8] can_insert always gives false.

Posted: Thu Oct 01, 2015 4:21 pm
by Rseding91
The literal string is what you want in this instance.

Have you tried printing the name of the caption where it would run in code to make sure the name is what you think it is?

Re: [0.12.8] can_insert always gives false.

Posted: Thu Oct 01, 2015 6:15 pm
by matjojo
Rseding91 wrote:The literal string is what you want in this instance.

Have you tried printing the name of the caption where it would run in code to make sure the name is what you think it is?
well, assuming I also give the Item back according to the caption, Yes. The caption is good. this is the piece of the code defining the caption:

Code: Select all

game.player.gui.left.EE_energy_condenser.EE_flow_item_selector.EE_label_item_selector.caption = game.player.cursor_stack.name
this works.
and game.player.cursor_stack.name gives the literal name.
I don't need to print it because it actually is displayed on the label next to the button. So I know what it is.

Re: [0.12.8] can_insert always gives false.

Posted: Thu Oct 01, 2015 10:02 pm
by Choumiko
From your attached zip:

Code: Select all

if game.player.can_insert{name = game.player.gui.left.EE_energy_condenser.EE_flow_item_selector.EE_label_item_selector.caption, count = 1} == "true"
No "" around true :D

Re: [0.12.8] can_insert always gives false.

Posted: Fri Oct 02, 2015 12:28 am
by DaveMcW
You don't need to compare == true, the value is already a boolean.

Re: [0.12.8] can_insert always gives false.

Posted: Fri Oct 02, 2015 12:30 pm
by matjojo
Choumiko wrote:From your attached zip:

Code: Select all

if game.player.can_insert{name = game.player.gui.left.EE_energy_condenser.EE_flow_item_selector.EE_label_item_selector.caption, count = 1} == "true"
No "" around true :D
I tried both, I first just like you assumed it would be without "" but that didn't work, so I was like: "well, that's weird, it might be with "" then."

Re: [0.12.8] can_insert always gives false.

Posted: Fri Oct 02, 2015 12:31 pm
by matjojo
DaveMcW wrote:You don't need to compare == true, the value is already a boolean.

so it should be?:

Code: Select all

if game.player.can_insert{name = game.player.gui.left.EE_energy_condenser.EE_flow_item_selector.EE_label_item_selector.caption, count = 1} then
    --what to do when there is space
else
    --what to do if there's no space
end
I'll try this evening when I have time.

Re: [0.12.8] can_insert always gives false.

Posted: Fri Oct 02, 2015 1:52 pm
by kovarex
Yes, and for the sake of the test, you should also try just

Code: Select all

if game.player.can_insert{name = "iron-plate", count = 1} then
    --what to do when there is space
else
    --what to
to find out where the error is.

I will put it to pending until it is clear it is a Factorio error.

Re: [0.12.8] can_insert always gives false. [not a bug]

Posted: Fri Oct 02, 2015 4:13 pm
by matjojo
kovarex wrote:Yes, and for the sake of the test, you should also try just
--snip--
I will put it to pending until it is clear it is a Factorio error.
It indeed was a mistake at my side, not testing if == true did work.

My apologies for potentially taking some time and maybe even a little scare.