Author Topic: LUA Mapgen Problems  (Read 307 times)

Offline Catasteroid

  • Zombie Food
  • *
  • Posts: 3
    • View Profile
LUA Mapgen Problems
« on: March 10, 2017, 11:30:30 PM »
I've been experimenting with the LUA mapgen method to make an interesting procedural house with many potential variants and so far I've been met only by the same error from the game when attempting to generate the map;
Quote
DEBUG: map::saven grid (0,0,0) uninitialized!
FUNCTION: void map::saven(int, int, int)
FILE: src/map.cpp
LINE: 6524
From what I can gather that can only come about if a totally blank map of t_null had been generated which means the LUA code isn't actually being executed at all which is frustrating. Could anyone with more in-depth knowledge shine a light on this and either tell me what I'm doing wrong?
I'm using experimental build 6003 from the 3rd of December 2016 if that sheds any light on the matter.
Offending code below in spoiler/quote.
(click to show/hide)

Offline Coolthulhu

  • Contributor
  • Survivor
  • ****
  • Posts: 3729
    • View Profile
Re: LUA Mapgen Problems
« Reply #1 on: March 11, 2017, 01:17:16 AM »
A map is uninitialized if upper-left (coord 0,0) tile is null, not necessarily the entire map.
Try creating a minimal example that works and progressing from there. Or at least forcing different error message - I'm not sure if the Lua interface reports the errors properly.

Offline Kevin Granade

  • Administrator
  • Survivor
  • *****
  • Posts: 5447
  • I code dead people.
    • View Profile
Re: LUA Mapgen Problems
« Reply #2 on: March 11, 2017, 03:11:26 AM »
Just a warning, LUA support is under the axe, we haven't had any significant use out of it, and we've sunk a LOT of effort into it, it's probably going to be gone by June or so.
Its like a fun family cookout, except your family is burning in flames while trying to eat you. -secretfire
I'm more excited than a survivor on meth and toast'ems. -Nighthawk
The the giant wasp is slammed through the zombie brute!

Offline Catasteroid

  • Zombie Food
  • *
  • Posts: 3
    • View Profile
Re: LUA Mapgen Problems
« Reply #3 on: March 12, 2017, 03:20:59 PM »
After some further experimentation I simply can't get a result out of the LUA mapgen method or the lua json method entry even using a single line of map:fill_background or map:draw_fill_backround or other variations without the same result of the game complaining about 0,0 0,1 1,0 and 1,1 being uninitialized then failing to generate submaps b before promptly crashing.
I'm aware it's days are numbered that's kind of what prompted me to play around with it before it's gone and I'm not expecting anyone to put any further effort into it if there is some underlying backend problem preventing this. If anyone's experimented with using LUA to spice up mapgen I'd appreciate it if you shared your experience with it.

Offline Zhilkin

  • NPC
  • **
  • Posts: 134
    • View Profile
Re: LUA Mapgen Problems
« Reply #4 on: June 08, 2017, 04:12:02 PM »
You need to use `map:draw_square_ter` function, not `square_ter`, also you need to provide `ter_str_id`, not a string as first parameter of this function.

Code will be like this:
Code: [Select]
map:draw_square_ter(ter_str_id("t_grass"),0,0,23,23)

***

Same for `line_ter` and `line_furn` functions, which should be `draw_line_ter` and `draw_line_furn`.

***

Functions `ter_set`/`furn_set` takes `tripoint` and `ter_str_id`/`furn_str_id` as arguments, so it will be like this:

Code: [Select]
map:ter_set(tirpoint(16,10,0),ter_str_id("t_console"))
map:furn_set(tripoint(18,13,0),furn_str_id("f_indoor_plant"))

***

Function `game.rng` takes two `int` parameters.

***

It is possible to move script to external file:

Code: [Select]
        "script": [
          "dofile('./data/json/mapgen_lua/dojo.lua')"
        ]

***

When lua mapgen script is in external file it will also be easier to test it using LUA debug console and following command:

Code: [Select]
dofile('./data/json/mapgen_lua/dojo.lua')

***

Here is an example: https://www.dropbox.com/s/pm8rpd1bhkhu9f5/cdda_lua_mapgen_example.zip?dl=0

`dojo` building was replaced with your house using lua mapgen


***


Here is another example: https://www.dropbox.com/s/3gn2p4sgmt5gdmz/cdda_mapgen_mil_surplus.zip?dl=0

`mil_surplus` buidling using lua mapgen (don't mind excess amount of loot - i didn't add check for loot spawn chance yet )
« Last Edit: June 08, 2017, 07:40:17 PM by Zhilkin »