MissSora22 Posted April 28, 2019 Share Posted April 28, 2019 This might be a very stupid question, I searched and tried for 2 days and nothing workes. In this forums, Steam, Google... I just want a selected prefab to generate exactly 1 time in the world. With AddRoomPreInit I only manage to make non or more. Than I tried to make a setpiece with the tutorials in this forum and tiles and put it in, but it never worked. Can somone help me with my stupidity? Link to comment https://forums.kleientertainment.com/forums/topic/105513-prefab-exactly-1-time-in-the-world/ Share on other sites More sharing options...
Ultroman Posted April 28, 2019 Share Posted April 28, 2019 Wherever you're spawning these, can't you set a variable on GLOBAL or TheWorld or something, telling you whether your spawning code has been called once? Full disclosure, I don't know if this works, but I think if you just do something like this, you should be able to lock it to 1. AddRoomPreInit("SomeRoom", function(room) if not GLOBAL.hasAddedMyThingamagig then -- do your thing GLOBAL.hasAddedMyThingamagig = true end end) Link to comment https://forums.kleientertainment.com/forums/topic/105513-prefab-exactly-1-time-in-the-world/#findComment-1186957 Share on other sites More sharing options...
MissSora22 Posted April 29, 2019 Author Share Posted April 29, 2019 (edited) Thank you. AddRoomPreInit("rainforest_lillypond", function(room) if not GLOBAL.contents.countprefabs then room.contents.countprefabs {} GLOBAL.contents.countprefabs {} = true end room.contents.countprefabs["octopusking"] = 1 end) This was what I tried, but it only crashed. Sill much thanks for your suggestion. Perhaps you can see were the problem is. Edited April 29, 2019 by MissSora22 Link to comment https://forums.kleientertainment.com/forums/topic/105513-prefab-exactly-1-time-in-the-world/#findComment-1187099 Share on other sites More sharing options...
Ultroman Posted April 29, 2019 Share Posted April 29, 2019 (edited) When encountering and inquiring about crashes, we need to see the crash log in order to help. If you do not know what I'm talking about, check out the debugging chapter of my newcomer post. That said, you seem to have some things messed up there. You're using both GLOBAL.contents and room.contents. Now, I don't know what contents is, since I've never done world generation stuff, but I'd guess the room has the contents table. Anyway, I thought you wanted to ensure a certain count for a prefab for the entire world. Not just this room. Have I misunderstood? Also, you're not declaring your table correctly. This is how you'd declare a table: room.contents.countprefabs = {} And to add a value to it: room.contents.countprefabs.myThing = true or room.contents.countprefabs[myThing] = true Try this code instead. This would spawn the octopus king in the first rainforest_lillypond generated, but never more than once: AddRoomPreInit("rainforest_lillypond", function(room) if not GLOBAL.has_octopusking then -- TODO: Spawn octopus king GLOBAL.has_octopusking = true end end) That said, octopus_king will be spawned by the world generator in the coral reefs, and we can't really stop that. This would just make sure that only one of him would be spawned in rainforest_lillypond, since he doesn't normally spawn there. Alternatively, you can wait until after world generation, search for all the octopus kings, and remove all but 1 xD Edited April 29, 2019 by Ultroman Link to comment https://forums.kleientertainment.com/forums/topic/105513-prefab-exactly-1-time-in-the-world/#findComment-1187120 Share on other sites More sharing options...
MissSora22 Posted April 29, 2019 Author Share Posted April 29, 2019 I tried it with AddRoomPreInit("rainforest_lillypond", function(room) if not GLOBAL.has_octopusking then room.contents.countprefabs["octopusking"] = 1 GLOBAL.has_octopusking = true end end) but it crashed again. I add the log log.txt Perhaps you can help me if we look from a different direction: This is what I tried first: AddRoomPreInit("rainforest_lillypond", function(room) if not room.contents.countprefabs then room.contents.countprefabs = {} end room.contents.countprefabs["octopusking"] = 1 end) Can you tell me why it doesn`t give me exactly 1 Octopusking in my Hamlet World? And sorry for my english and if I don`t understand somthing. I`m not a native speaker. Link to comment https://forums.kleientertainment.com/forums/topic/105513-prefab-exactly-1-time-in-the-world/#findComment-1187267 Share on other sites More sharing options...
Ultroman Posted April 29, 2019 Share Posted April 29, 2019 55 minutes ago, MissSora22 said: Can you tell me why it doesn`t give me exactly 1 Octopusking in my Hamlet World? No, I cannot. I have no idea how rooms work The error says [00:00:25]: F:/Programme/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(44,1) error calling RoomPreInit: rainforest_lillypond in mod My Mod - Meeting old friends 1.0.1 (Meeting old friends 1.0.1): ... Mod - Meeting old friends 1.0.1/modworldgenmain.lua:2: variable 'has_octopusking' is not declared So, on line 44 it ran into an error stating that has_octopusking is not declared. Apparently we cannot just add something to GLOBAL like that. I don't know what to do here, sorry. Link to comment https://forums.kleientertainment.com/forums/topic/105513-prefab-exactly-1-time-in-the-world/#findComment-1187309 Share on other sites More sharing options...
MissSora22 Posted April 29, 2019 Author Share Posted April 29, 2019 Still thank you very much Link to comment https://forums.kleientertainment.com/forums/topic/105513-prefab-exactly-1-time-in-the-world/#findComment-1187314 Share on other sites More sharing options...
MissSora22 Posted April 30, 2019 Author Share Posted April 30, 2019 I think I made it happen! Perhabs not in the most elegant way, but it seemed to work and since I posted my question here and used up all your guys time and effort think it would only be fair to post my solution here, perhabs it will help someone at sometime. The Problem with this: AddRoomPreInit("rainforest_lillypond", function(room) if not room.contents.countprefabs then room.contents.countprefabs = {} end room.contents.countprefabs["octopusking"] = 1 end) was that the room "rainforest_lillypond" exists severel times in a Hamlet World, so I got an octopusking in every "rainforest_lillypond" room. So I created a new room: GLOBAL.require("constants") local GROUND = GLOBAL.GROUND AddRoom("Octopuspond", { colour={r=1.,g=0.3,b=0.3,a=0.3}, value = GROUND.LILYPOND, tags = {"Bramble"}, contents = { countprefabs = { octopusking = 1, }, distributepercent = 0.3, distributeprefabs = { fishinhole = .75, coralreef = 1, ballphinhouse = .1, seaweed_planted = .3, jellyfish_planted = .3, rainbowjellyfish_planted = 0.2, solofish = .3, reeds_water = 3, lotus = 2, ox = 0.2, hippopotamoose = 0.2, relic_1 = 0.04, relic_2 = 0.04, relic_3 = 0.04 }, }}) and added it one time to one of the early Worldbuilding tasks: local function MakePickTaskPreInit(task) task.room_choices["Octopuspond"] = 1 end AddTaskPreInit("rainforests", MakePickTaskPreInit) (all in the modworldgenmain.lua, by the way) Thanks again to all of you, especially to Ultroman, who helped me understand a lot of this clearer. Link to comment https://forums.kleientertainment.com/forums/topic/105513-prefab-exactly-1-time-in-the-world/#findComment-1187542 Share on other sites More sharing options...
Ultroman Posted April 30, 2019 Share Posted April 30, 2019 (edited) I didn't do anything. This was all you Great job figuring this out! Edited April 30, 2019 by Ultroman Link to comment https://forums.kleientertainment.com/forums/topic/105513-prefab-exactly-1-time-in-the-world/#findComment-1187548 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now