zVince Posted April 14, 2020 Share Posted April 14, 2020 Hello. I've been working on a personal mod that aims to bring the Shipwrecked generation of seas to the Reign of Giants. Trying to implement the volcano in the Reign of Giants I fall into a problem, the volcano's save is shared between sw and rog.So I'm trying to find a way to make the entry and exit dynamic. In which if I enter through RoG, I need to leave through RoG, and if I enter through Sw, I have to exit through Sw... The first solution that came to mind is, upon entering RoG, a global variable receives one value, and upon entering Sw receives another. So when I tried to leave the volcano, this variable would be requested to inform where the exit would be.The problem is that when entering the volcano the value of this variable is lost. How to solve this? What would be a viable alternative? (I'm new to programming) Link to comment Share on other sites More sharing options...
zVince Posted April 14, 2020 Author Share Posted April 14, 2020 I found a solution to the problem. If someone needs to resolve something similar in the future, below is the code. It works as follows: When entering the rog or sw world will generate a entrace_log_ file(save_slot).lua in your mod folder. Where will store "0" for the RoG world and "1" for the Shipwrecked world. The value will be stored in the file after entering the world, replacing the previous value. If you need to redeem the value, just request to read the file in a condition and apply it to a global variable, so the variable can be used anywhere in the mod. Spoiler (in modmain.lua) AddPrefabPostInit("world", function(inst) file_name = MODROOT.."entrace_log_"..tostring(GLOBAL.SaveGameIndex:GetCurrentSaveSlot())..".lua" if GLOBAL.SaveGameIndex:GetCurrentMode() == "shipwrecked" then file = io.open(file_name, "w") file:write(1) file:close() elseif GLOBAL.SaveGameIndex:GetCurrentMode() == "survival" then file = io.open(file_name, "w") file:write(0) file:close() end if GLOBAL.SaveGameIndex:GetCurrentMode() == "volcano" then file = io.open(file_name, "r") GLOBAL.TUNING.WORLDMODE = file:read() file:close() end end) I also thank you for this topic. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.