Problems with my first szenario

Place to get help with not working mods / modding interface.
Stumpyofpain
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Jun 06, 2017 4:31 pm
Contact:

Problems with my first szenario

Post by Stumpyofpain »

good day

I would like to start creating my own scenarios and have read the "Modding Info References" and then tried to adapt the "tutorial lvl 2" to my needs.

but I have a problem with the following section.

i thought that if i place an item in the game editor, give it an entity tag and then query it in the lua so that it will be stored there in the variable when the game state starts.

Code: Select all

local init = function()

  global.story = story_init()
  game.map_settings.pollution.enabled = false

  global.inserter_chest = game.get_entity_by_tag("inserter-chest")  or error("Inserter chest missing")
  global.inserter_chest_position = global.inserter_chest.position
  global.inserter_chest_position.energy = 0

  global.inserter_furnace = game.get_entity_by_tag("inserter-furnace") or error("Inserter furnace missing")
  global.inserter_furnace_position = global.inserter_furnace.position
end
how i proceeded:
I copied the lvl 2 of the tutorial into my scenario folder.
afterwards i played the tutorial and looked at what which code section does and made notes about it.

then i made minor adjustments (allowing other recipes, completing research, etc.) inside the control.lua which were all successful.

after that i tried to adjust the inserter, but it fails every time and i don't know what the reason could be.


first i had deleted the inserter and replaced it with fast inserter, replaced the entity-tag and also replaced it in the code.
but when I then started, he said directly that I had deconstructed the inserter and should place it again.
so I thought I had made a mistake in doing so and restored the previous status.

currently I have tested that it works when I do not change anything or when i only change the entity-tag ingame or inside the lua.
it dosnt matter what entity-tag i insert.

As soon as I remove the inserter and place it again, i get the error message, that i deconstructed the inserter, even if i add the correct entity-tag.

can someone please explain to me what I am doing wrong?

greetings
Stumpy
Attachments
factorio_entity_tag_error.png
factorio_entity_tag_error.png (101.62 KiB) Viewed 2106 times
factorio_entity_tag.jpg
factorio_entity_tag.jpg (14.48 KiB) Viewed 2106 times
Stumpyofpain
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Jun 06, 2017 4:31 pm
Contact:

Re: Problems with my first szenario

Post by Stumpyofpain »

I had to create a new map in freeplay.
There I can now freely change and query the "entity-tag".


Now I wanted to start with the story itself.
I have taken some code snippets from the tutorial, but I always got an error "on_event" of my story.
So I looked in "Factorio --> Core --> lualib" and saw, that there is a story skeleton, which I inserted in my control.lua.

Even with that code I get the same error.
I deleted everything else in my control.lua to check, that its not anything i did write before.

Right now my control.lua looks like this.

Code: Select all

require "story"

--Init the story script
script.on_init(function()
  global.story = story_init()
end)


--Register the update to all events
script.on_event(defines.events, function(event)
  story_update(global.story, event)
end)


--[[
--Can also register to specific events, if you want to do multiple things with that event
script.on_event(defines.events.on_tick, function(event)
  story_update(global.story, event)
  --Other things on tick can go here.
end)
]]
story_table =
{
  {
	--branch 1
    {
      init = function(event, story)
        game.print("Welcome players")
        set_goal("Enjoy the scenery for 5 seconds")
      end,
      condition = story_elapsed_check(5)
    },
    {
      init = function(event, story)
        game.print("Enough relaxation, time to automate!")
        set_goal("Automate it!")
        set_info{text = "Automating things is a lot of fun, trust me"}
        for k, player in pairs (game.players) do
          player.insert("iron-plate")
        end
      end,
      update = function(event, story)
        if event.name == defines.events.on_player_crafted_item then
          game.players[event.player_index].print({"", "You crafted a ", game.item_prototypes[event.item_stack.name].localised_name})
        end
      end,
      condition = function(event)
        return event.name == defines.events.on_built_entity
      end,
      action = function(event)
        game.print({"", game.players[event.player_index].name, " built a ", event.created_entity.localised_name})
      end
    },
    {
      init = function()
        set_goal("Thats it guys!")
        set_info()
      end,
      condition = story_elapsed_check(5)
    }
  },
  {
	--branch 2
  }
}

story_init_helpers(story_table)
the error i get is the following one

Code: Select all

Szenario level hat einen Fehler verursacht, der nicht behoben werden kann.
Bitte informiere den Autor des Szenarios über diesen Fehler.

Error while running event level::on_pre_player_removed (ID 136)
__core__/lualib/story.lua:44: attempt to index local 'story' (a nil value)
stack traceback:
	__core__/lualib/story.lua:44: in function 'story_update'
	...Data/Roaming/Factorio/temp/currently-playing/control.lua:11: in function <...Data/Roaming/Factorio/temp/currently-playing/control.lua:10>
Line 11 in my control.lua is the "script.on_event"

Code: Select all

--Register the update to all events
script.on_event(defines.events, function(event)
  story_update(global.story, event)
end)
when i look for line 44 in the story.lua there is the following line

Code: Select all

  local branches = story_branches[story.story_index]
as you can see, i am not the only one with that problem, but sadly that was already 1 1/2 years ago and there was no fix for it.

viewtopic.php?f=25&t=88259&p=507888&hil ... ed#p507888
Stumpyofpain
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Jun 06, 2017 4:31 pm
Contact:

Re: Problems with my first szenario

Post by Stumpyofpain »

I have now managed to create my first scenario.
I used a map from the mod "Story-Missions_2.1.7" from "GreenFlag" and removed everything I did not need and built my own queries and story to it.

now i want to create a second version of the scenario where my students have to buy assembly machines, inserters etc. in a store and place them in a defined area.

if i get additional errors, i will come back here :)
Pi-C
Smart Inserter
Smart Inserter
Posts: 1734
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Problems with my first szenario

Post by Pi-C »

Stumpyofpain wrote: Sat Jun 04, 2022 8:58 am

Code: Select all

...Data/Roaming/Factorio/temp/currently-playing/control.lua:32: attempt to index global 'Event' (a nil value)
You've never defined Event. I'd guess the scenario you've copied your code from uses an external mod (possibly Factorio Standard Library) to manage the event handlers. If you want to do the same, you must add a dependency on the library mod. Of course, you could also register events the old-fashioned way, using the functions provided by LuaBootstrap.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Stumpyofpain
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Jun 06, 2017 4:31 pm
Contact:

Re: Problems with my first szenario

Post by Stumpyofpain »

ty for your reply.
i found out that it was just another event handler, which dosnt work with the other handler together.
because of it, i changed it back und i do the initial setup of the shops and other important variables with a button. (its only needed when i change something in the szenario itself)

the most i planned to do works now.

now i have 2 problems

1. every time i edit my szenario and press "save and play", the image for the szenario gets deleted. why?

2. is there an easy way to block placing entities on any ground?
when my player runs out of money, he isnt allowed to place anything, until he sells something or handmines some entities.
right now, they can place as long as they want, which causes them to get unlimited money.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1734
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Problems with my first szenario

Post by Pi-C »

Stumpyofpain wrote: Sun Jun 05, 2022 10:50 pm now i have 2 problems

1. every time i edit my szenario and press "save and play", the image for the szenario gets deleted. why?
I've never made a scenario, so I can't say anything about this.
2. is there an easy way to block placing entities on any ground?
when my player runs out of money, he isnt allowed to place anything, until he sells something or handmines some entities.
right now, they can place as long as they want, which causes them to get unlimited money.
You may want to check out the events.

Use on_built_entity to check whether the player has enough money. If not, destroy the built entity and store a may_not_build flag for the player in global. Use on_pre_player_mined_item or on_player_mined_entity to remove that flag again if the player mined something. Checking whether the player has sold something is more complicated. There's only on_market_item_purchased, but that doesn't tell you when a player sold something.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Stumpyofpain
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Jun 06, 2017 4:31 pm
Contact:

Re: Problems with my first szenario

Post by Stumpyofpain »

ty Pi-C
it was much easier than I had thought.
yesterday I was afraid that I would have to use a collision mask but your solution is much simpler and clearer.

i already implemented the buy back / tear down / hand mining yesterday.
for this i check all placed items and multiply their number with a certain area value and get the area cost.
so if they tear something down, the value is different than before and the money is refunded.

and for selling items i also have a box where things can be put in, for which the students then get coins.

I will now do a little bug testing and hope that everything fits so and I can then complete the level and the story.
Post Reply

Return to “Modding help”