Fix #4111 ("Provided world path doesn't exist" if choosing singleplayer on first...
authorRui <Rui914@users.noreply.github.com>
Thu, 12 May 2016 15:38:29 +0000 (01:38 +1000)
committerCraig Robbins <kde.psych@gmail.com>
Thu, 12 May 2016 15:41:16 +0000 (01:41 +1000)
Bug and whitespace error fixed (Zeno)

builtin/mainmenu/init.lua

index 6dd345ff476c1ca43f74a6c6519b4e02246b769f..7f0c1e386041da5495b57103301dcb9d7cab6bae 100644 (file)
@@ -77,13 +77,28 @@ local function init_globals()
 
        if PLATFORM == "Android" then
                local world_list = core.get_worlds()
-               local world_index = table.indexof(world_list, "singleplayerworld")
+               local world_index
+
+               local found_singleplayerworld = false
+               for i, world in ipairs(world_list) do
+                       if world.name == "singleplayerworld" then
+                               found_singleplayerworld = true
+                               world_index = i
+                               break
+                       end
+               end
 
-               if world_index == -1 then
+               if not found_singleplayerworld then
                        core.create_world("singleplayerworld", 1)
 
                        world_list = core.get_worlds()
-                       world_index = table.indexof(world_list, "singleplayerworld")
+
+                       for i, world in ipairs(world_list) do
+                               if world.name == "singleplayerworld" then
+                                       world_index = i
+                                       break
+                               end
+                       end
                end
 
                gamedata.worldindex = world_index