Index: code/branches/gamestates3/data/gui/scripts/AudioMenu.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/AudioMenu.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/AudioMenu.lua	(revision 6773)
@@ -4,162 +4,162 @@
 
 function P.onLoad()
-    soundMgr = orxonox.SoundManager:getInstance()
-    block = false
-    masterscrollbar_active = false
-    musicscrollbar_active = false
-    effectsscrollbar_active = false
-    mastervolume = soundMgr:getVolume(orxonox.SoundType.All)
-    musicvolume = soundMgr:getVolume(orxonox.SoundType.Music)
-    effectsvolume = soundMgr:getVolume(orxonox.SoundType.Effects)
-    mastermute = soundMgr:getMute(orxonox.SoundType.All)
-    musicmute = soundMgr:getMute(orxonox.SoundType.Music)
-    effectsmute = soundMgr:getMute(orxonox.SoundType.Effects)
-    masterscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MasterScrollbar"),"CEGUI::Scrollbar")
-    musicscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MusicScrollbar"),"CEGUI::Scrollbar")
-    effectsscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/EffectsScrollbar"),"CEGUI::Scrollbar")
-    mastermutewindow = tolua.cast(winMgr:getWindow("orxonox/MasterCheckbox"),"CEGUI::Checkbox")
-    musicmutewindow = tolua.cast(winMgr:getWindow("orxonox/MusicCheckbox"),"CEGUI::Checkbox")
-    effectsmutewindow = tolua.cast(winMgr:getWindow("orxonox/EffectsCheckbox"),"CEGUI::Checkbox")
-    masterscrollbarwindow:setScrollPosition(mastervolume)
-    musicscrollbarwindow:setScrollPosition(musicvolume)
-    effectsscrollbarwindow:setScrollPosition(effectsvolume)
-    mastermutewindow:setSelected(mastermute)
-    musicmutewindow:setSelected(musicmute)
-    effectsmutewindow:setSelected(effectsmute)
-    choice = "Default"
-    listboxwindow = winMgr:getWindow("orxonox/AudioThemeListbox")
+    P.soundMgr = orxonox.SoundManager:getInstance()
+    P.block = false
+    P.masterscrollbar_active = false
+    P.musicscrollbar_active = false
+    P.effectsscrollbar_active = false
+    P.mastervolume = P.soundMgr:getVolume(orxonox.SoundType.All)
+    P.musicvolume = P.soundMgr:getVolume(orxonox.SoundType.Music)
+    P.effectsvolume = P.soundMgr:getVolume(orxonox.SoundType.Effects)
+    P.mastermute = P.soundMgr:getMute(orxonox.SoundType.All)
+    P.musicmute = P.soundMgr:getMute(orxonox.SoundType.Music)
+    P.effectsmute = P.soundMgr:getMute(orxonox.SoundType.Effects)
+    P.masterscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MasterScrollbar"),"CEGUI::Scrollbar")
+    P.musicscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MusicScrollbar"),"CEGUI::Scrollbar")
+    P.effectsscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/EffectsScrollbar"),"CEGUI::Scrollbar")
+    P.mastermutewindow = tolua.cast(winMgr:getWindow("orxonox/MasterCheckbox"),"CEGUI::Checkbox")
+    P.musicmutewindow = tolua.cast(winMgr:getWindow("orxonox/MusicCheckbox"),"CEGUI::Checkbox")
+    P.effectsmutewindow = tolua.cast(winMgr:getWindow("orxonox/EffectsCheckbox"),"CEGUI::Checkbox")
+    P.masterscrollbarwindow:setScrollPosition(P.mastervolume)
+    P.musicscrollbarwindow:setScrollPosition(P.musicvolume)
+    P.effectsscrollbarwindow:setScrollPosition(P.effectsvolume)
+    P.mastermutewindow:setSelected(P.mastermute)
+    P.musicmutewindow:setSelected(P.musicmute)
+    P.effectsmutewindow:setSelected(P.effectsmute)
+    local choice = "Default"
+    P.listboxwindow = winMgr:getWindow("orxonox/AudioThemeListbox")
     local themeList = {}
     table.insert(themeList, "Default")
     table.insert(themeList, "Drum n' Bass")
     for k,v in pairs(themeList) do
-        item = CEGUI.createListboxTextItem(v)
+        local item = CEGUI.createListboxTextItem(v)
         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
-        CEGUI.toListbox(listboxwindow):addItem(item)
+        CEGUI.toListbox(P.listboxwindow):addItem(item)
     end
     if orxonox.getConfig("MoodManager", "mood_") == "dnb" then
-        listboxwindow:setItemSelectState(1,true)
+        P.listboxwindow:setItemSelectState(1,true)
     else
-        listboxwindow:setItemSelectState(0,true)
+        P.listboxwindow:setItemSelectState(0,true)
     end
 end
 
 function P.AudioMasterScrollbar_changed(e)
-    if mastermute then
-        block = true
-        mastermutewindow:setSelected(false)
-        block = false
-        mastermute = false
+    if P.mastermute then
+        P.block = true
+        P.mastermutewindow:setSelected(false)
+        P.block = false
+        P.mastermute = false
     end
-    if masterscrollbar_active == false then
-        mastervolume = masterscrollbarwindow:getScrollPosition()
-        orxonox.config("SoundManager", "soundVolume_", mastervolume)
+    if P.masterscrollbar_active == false then
+        P.mastervolume = P.masterscrollbarwindow:getScrollPosition()
+        orxonox.config("SoundManager", "soundVolume_", P.mastervolume)
     end
 end
 
 function P.AudioMasterScrollbar_started(e)
-    masterscrollbar_active = true
+    P.masterscrollbar_active = true
 end
 
 function P.AudioMasterScrollbar_ended(e)
-    mastervolume = masterscrollbarwindow:getScrollPosition()
-    orxonox.config("SoundManager", "soundVolume_", mastervolume)
-    masterscrollbar_active = false
+    P.mastervolume = P.masterscrollbarwindow:getScrollPosition()
+    orxonox.config("SoundManager", "soundVolume_", P.mastervolume)
+    P.masterscrollbar_active = false
 end
 
 function P.AudioMusicScrollbar_changed(e)
-    if musicmute then
-        block = true
-        musicmutewindow:setSelected(false)
-        block = false
-        musicmute = false
+    if P.musicmute then
+        P.block = true
+        P.musicmutewindow:setSelected(false)
+        P.block = false
+        P.musicmute = false
     end
-    if musicscrollbar_active == false then
-        musicvolume = musicscrollbarwindow:getScrollPosition()
-        orxonox.config("SoundManager", "ambientVolume_", musicvolume)
+    if P.musicscrollbar_active == false then
+        P.musicvolume = P.musicscrollbarwindow:getScrollPosition()
+        orxonox.config("SoundManager", "ambientVolume_", P.musicvolume)
     end
 end
 
 function P.AudioMusicScrollbar_started(e)
-    musicscrollbar_active = true
+    P.musicscrollbar_active = true
 end
 
 function P.AudioMusicScrollbar_ended(e)
-    musicmutewindow:setSelected(false)
-    musicvolume = musicscrollbarwindow:getScrollPosition()
-    orxonox.config("SoundManager", "ambientVolume_", musicvolume)
-    musicscrollbar_active = false
+    P.musicmutewindow:setSelected(false)
+    P.musicvolume = P.musicscrollbarwindow:getScrollPosition()
+    orxonox.config("SoundManager", "ambientVolume_", P.musicvolume)
+    P.musicscrollbar_active = false
 end
 
 function P.AudioEffectsScrollbar_changed(e)
-    if effectsmute then
-        block = true
-        effectsmutewindow:setSelected(false)
-        block = false
-        effectsmute = false
+    if P.effectsmute then
+        P.block = true
+        P.effectsmutewindow:setSelected(false)
+        P.block = false
+        P.effectsmute = false
     end
-    if effectsscrollbar_active == false then
-        effectsvolume = effectsscrollbarwindow:getScrollPosition()
-        orxonox.config("SoundManager", "effectsVolume_", effectsvolume)
+    if P.effectsscrollbar_active == false then
+        P.effectsvolume = P.effectsscrollbarwindow:getScrollPosition()
+        orxonox.config("SoundManager", "effectsVolume_", P.effectsvolume)
     end
 end
 
 function P.AudioEffectsScrollbar_started(e)
-    effectsscrollbar_active = true
+    P.effectsscrollbar_active = true
 end
 
 function P.AudioEffectsScrollbar_ended(e)
-    effectsmutewindow:setSelected(false)
-    effectsvolume = effectsscrollbarwindow:getScrollPosition()
-    orxonox.config("SoundManager", "effectsVolume_", effectsvolume)
-    effectsscrollbar_active = false
+    P.effectsmutewindow:setSelected(false)
+    P.effectsvolume = P.effectsscrollbarwindow:getScrollPosition()
+    orxonox.config("SoundManager", "effectsVolume_", P.effectsvolume)
+    P.effectsscrollbar_active = false
 end
 
 function P.AudioMuteMasterCheckbox_clicked(e)
-    if block == false then
-        if mastermute then
-            masterscrollbarwindow:setScrollPosition(mastervolume)
-            mastermute = false
+    if P.block == false then
+        if P.mastermute then
+            P.masterscrollbarwindow:setScrollPosition(P.mastervolume)
+            P.mastermute = false
         else
-            temp = masterscrollbarwindow:getScrollPosition()
-            masterscrollbarwindow:setScrollPosition(0)
-            mastervolume = temp
-            mastermute = true
+            temp = P.masterscrollbarwindow:getScrollPosition()
+            P.masterscrollbarwindow:setScrollPosition(0)
+            P.mastervolume = temp
+            P.mastermute = true
         end
     end
-    soundMgr:toggleMute(orxonox.SoundType.All)
+    P.soundMgr:toggleMute(orxonox.SoundType.All)
 end
 
 function P.AudioMuteMusicCheckbox_clicked(e)
-    if block == false then
-        if musicmute then
-            musicscrollbarwindow:setScrollPosition(musicvolume)
-            musicmute = false
+    if P.block == false then
+        if P.musicmute then
+            P.musicscrollbarwindow:setScrollPosition(P.musicvolume)
+            P.musicmute = false
         else
-            temp = musicscrollbarwindow:getScrollPosition()
-            musicscrollbarwindow:setScrollPosition(0)
-            musicvolume = temp
-            musicmute = true
+            temp = P.musicscrollbarwindow:getScrollPosition()
+            P.musicscrollbarwindow:setScrollPosition(0)
+            P.musicvolume = temp
+            P.musicmute = true
         end
     end
-    soundMgr:toggleMute(orxonox.SoundType.Music)
+    P.soundMgr:toggleMute(orxonox.SoundType.Music)
 end
 
 function P.AudioMuteEffectsCheckbox_clicked(e)
-    if block == false then
-        if effectsmute then
-            effectsscrollbarwindow:setScrollPosition(effectsvolume)
-            effectsmute = false
+    if P.block == false then
+        if P.effectsmute then
+            P.effectsscrollbarwindow:setScrollPosition(P.effectsvolume)
+            P.effectsmute = false
         else
-            temp = effectsscrollbarwindow:getScrollPosition()
-            effectsscrollbarwindow:setScrollPosition(0)
-            effectsvolume = temp
-            effectsmute = true
+            temp = P.effectsscrollbarwindow:getScrollPosition()
+            P.effectsscrollbarwindow:setScrollPosition(0)
+            P.effectsvolume = temp
+            P.effectsmute = true
         end
     end
-    soundMgr:toggleMute(orxonox.SoundType.Effects)
+    P.soundMgr:toggleMute(orxonox.SoundType.Effects)
 end
 
 function P.AudioThemeListbox_changed(e)
-    if listboxwindow:isItemSelected(1) then
+    if P.listboxwindow:isItemSelected(1) then
         orxonox.config("MoodManager", "mood_", "dnb")
     else
Index: code/branches/gamestates3/data/gui/scripts/GUITools.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/GUITools.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/GUITools.lua	(revision 6773)
@@ -3,4 +3,5 @@
 function createMenuSheet(name, bHidePrevious, tShowCursor, tUseKeyboard, bBlockJoyStick)
     local sheet = require("MenuSheet").new(name, bHidePrevious, tShowCursor, tUseKeyboard, bBlockJoyStick)
+    global(sheet.name)
     _G[sheet.name] = sheet -- Global access required because of the event handlers
     return sheet
Index: code/branches/gamestates3/data/gui/scripts/GameplayMenu.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/GameplayMenu.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/GameplayMenu.lua	(revision 6773)
@@ -4,5 +4,5 @@
 
 function P.onLoad()
-    dropdown = winMgr:getWindow("orxonox/ThemeCombobox")
+    local dropdown = winMgr:getWindow("orxonox/ThemeCombobox")
     local themeList = {}
     table.insert(themeList, "Theme 1")
Index: code/branches/gamestates3/data/gui/scripts/GraphicsMenu.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/GraphicsMenu.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/GraphicsMenu.lua	(revision 6773)
@@ -4,29 +4,29 @@
 
 function P.onLoad()
-    block = true
-    file = orxonox.PathConfig:getConfigPathString() .. orxonox.getConfig("GraphicsManager", "ogreConfigFile_")
-    search_mode = 0
-    f = io.open(file, "r")
-    firstline = f:read("*line")
-    rendersystem = string.sub(firstline, 15)
+    P.block = true
+    P.file = orxonox.PathConfig:getConfigPathString() .. orxonox.getConfig("GraphicsManager", "ogreConfigFile_")
+    P.search_mode = 0
+    local f = io.open(P.file, "r")
+    local firstline = f:read("*line")
+    local rendersystem = string.sub(firstline, 15)
     for line in f:lines() do
-        if search_mode == 0 then
+        if P.search_mode == 0 then
             if string.find(line, rendersystem) ~= nil then
-                search_mode = 1
+                P.search_mode = 1
             end
         end
-        if search_mode == 1 then
+        if P.search_mode == 1 then
             if string.sub(line, 1, 11) == "Full Screen" then
                 if string.sub(line, 13) == "Yes" then
-                    fullscreen = true
+                    P.fullscreen = true
                 else
-                    fullscreen = false
+                    P.fullscreen = false
                 end
             end
             if string.sub(line, 1, 10) == "Video Mode" then
                 if string.match(line, "@") == "@" then
-                    resolution = string.sub(line, 12, string.find(line, "@")-2)
+                    P.resolution = string.sub(line, 12, string.find(line, "@")-2)
                 else
-                    resolution = string.sub(line, 12)
+                    P.resolution = string.sub(line, 12)
                 end
                 break
@@ -36,6 +36,6 @@
     f:close()
     local fullscreenwindow = tolua.cast(winMgr:getWindow("orxonox/FullscreenCheckbox"),"CEGUI::Checkbox")
-    fullscreenwindow:setSelected(fullscreen)
-    listboxwindow = winMgr:getWindow("orxonox/ResolutionListbox")
+    fullscreenwindow:setSelected(P.fullscreen)
+    P.listboxwindow = winMgr:getWindow("orxonox/ResolutionListbox")
     local resolutionList = {}
     table.insert(resolutionList, "640 x 480")
@@ -52,82 +52,82 @@
     table.insert(resolutionList, "1440 x 900")
     for k,v in pairs(resolutionList) do
-        item = CEGUI.createListboxTextItem(v)
+        local item = CEGUI.createListboxTextItem(v)
         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
-        CEGUI.toListbox(listboxwindow):addItem(item)
+        CEGUI.toListbox(P.listboxwindow):addItem(item)
     end
-    if resolution == "640 x 480" then
-        listboxwindow:setItemSelectState(0,true)
-    elseif resolution == "720 x 480" then
-        listboxwindow:setItemSelectState(1,true)
-    elseif resolution == "720 x 576" then
-        listboxwindow:setItemSelectState(2,true)
-    elseif resolution == "800 x 480" then
-        listboxwindow:setItemSelectState(3,true)
-    elseif resolution == "800 x 600" then
-        listboxwindow:setItemSelectState(4,true)
-    elseif resolution == "1024 x 480" then
-        listboxwindow:setItemSelectState(5,true)
-    elseif resolution == "1024 x 600" then
-        listboxwindow:setItemSelectState(6,true)
-    elseif resolution == "1024 x 768" then
-        listboxwindow:setItemSelectState(7,true)
-    elseif resolution == "1152 x 864" then
-        listboxwindow:setItemSelectState(8,true)
-    elseif resolution == "1280 x 720" then
-        listboxwindow:setItemSelectState(9,true)
-    elseif resolution == "1280 x 768" then
-        listboxwindow:setItemSelectState(10,true)
-    elseif resolution == "1440 x 900" then
-        listboxwindow:setItemSelectState(11,true)
+    if P.resolution == "640 x 480" then
+        P.listboxwindow:setItemSelectState(0,true)
+    elseif P.resolution == "720 x 480" then
+        P.listboxwindow:setItemSelectState(1,true)
+    elseif P.resolution == "720 x 576" then
+        P.listboxwindow:setItemSelectState(2,true)
+    elseif P.resolution == "800 x 480" then
+        P.listboxwindow:setItemSelectState(3,true)
+    elseif P.resolution == "800 x 600" then
+        P.listboxwindow:setItemSelectState(4,true)
+    elseif P.resolution == "1024 x 480" then
+        P.listboxwindow:setItemSelectState(5,true)
+    elseif P.resolution == "1024 x 600" then
+        P.listboxwindow:setItemSelectState(6,true)
+    elseif P.resolution == "1024 x 768" then
+        P.listboxwindow:setItemSelectState(7,true)
+    elseif P.resolution == "1152 x 864" then
+        P.listboxwindow:setItemSelectState(8,true)
+    elseif P.resolution == "1280 x 720" then
+        P.listboxwindow:setItemSelectState(9,true)
+    elseif P.resolution == "1280 x 768" then
+        P.listboxwindow:setItemSelectState(10,true)
+    elseif P.resolution == "1440 x 900" then
+        P.listboxwindow:setItemSelectState(11,true)
     end
-    scrollbar_active = false
-    block = false
+    P.scrollbar_active = false
+    P.block = false
 end
 
 function P.GraphicsResolutionListbox_changed(e)
-    if listboxwindow:isItemSelected(0) then
-        resolution = "640 x 480"
-    elseif listboxwindow:isItemSelected(1) then
-        resolution = "720 x 480"
-    elseif listboxwindow:isItemSelected(2) then
-        resolution = "720 x 576"
-    elseif listboxwindow:isItemSelected(3) then
-        resolution = "800 x 480"
-    elseif listboxwindow:isItemSelected(4) then
-        resolution = "800 x 600"
-    elseif listboxwindow:isItemSelected(5) then
-        resolution = "1024 x 480"
-    elseif listboxwindow:isItemSelected(6) then
-        resolution = "1024 x 600"
-    elseif listboxwindow:isItemSelected(7) then
-        resolution = "1024 x 768"
-    elseif listboxwindow:isItemSelected(8) then
-        resolution = "1152 x 864"
-    elseif listboxwindow:isItemSelected(9) then
-        resolution = "1280 x 720"
-    elseif listboxwindow:isItemSelected(10) then
-        resolution = "1280 x 768"
-    elseif listboxwindow:isItemSelected(11) then
-        resolution = "1440 x 900"
+    if P.listboxwindow:isItemSelected(0) then
+        P.resolution = "640 x 480"
+    elseif P.listboxwindow:isItemSelected(1) then
+        P.resolution = "720 x 480"
+    elseif P.listboxwindow:isItemSelected(2) then
+        P.resolution = "720 x 576"
+    elseif P.listboxwindow:isItemSelected(3) then
+        P.resolution = "800 x 480"
+    elseif P.listboxwindow:isItemSelected(4) then
+        P.resolution = "800 x 600"
+    elseif P.listboxwindow:isItemSelected(5) then
+        P.resolution = "1024 x 480"
+    elseif P.listboxwindow:isItemSelected(6) then
+        P.resolution = "1024 x 600"
+    elseif P.listboxwindow:isItemSelected(7) then
+        P.resolution = "1024 x 768"
+    elseif P.listboxwindow:isItemSelected(8) then
+        P.resolution = "1152 x 864"
+    elseif P.listboxwindow:isItemSelected(9) then
+        P.resolution = "1280 x 720"
+    elseif P.listboxwindow:isItemSelected(10) then
+        P.resolution = "1280 x 768"
+    elseif P.listboxwindow:isItemSelected(11) then
+        P.resolution = "1440 x 900"
     end
-    search_mode = 0
-    f = io.open(file, "r")
-    firstline = f:read("*line")
-    text = firstline .. "\n"
-    rendersystem = string.sub(firstline, 15)
+    P.search_mode = 0
+    local f = io.open(P.file, "r")
+    local firstline = f:read("*line")
+    local text = firstline .. "\n"
+    local rendersystem = string.sub(firstline, 15)
     for line in f:lines() do
-        if search_mode == 0 then
+        if P.search_mode == 0 then
             if string.find(line, rendersystem) ~= nil then
-                search_mode = 1
+                P.search_mode = 1
             end
         end
-        if search_mode == 1 then
+        if P.search_mode == 1 then
             if string.sub(line, 1, 10) == "Video Mode" then
                 if string.match(line, "@") == "@" then
-                    line = "Video Mode=" .. resolution .. string.sub(line, string.find(line, "@")-1)
+                    line = "Video Mode=" .. P.resolution .. string.sub(line, string.find(line, "@")-1)
                 else
-                    line = "Video Mode=" .. resolution
+                    line = "Video Mode=" .. P.resolution
                 end
-                search_mode = 2
+                P.search_mode = 2
             end
         end
@@ -135,5 +135,5 @@
     end
     f:close()
-    f = io.open(file, "w")
+    f = io.open(P.file, "w")
     f:write(text)
     f:close()
@@ -141,5 +141,5 @@
 
 function P.GraphicsBrightnessScrollbar_changed(e)
-    if scrollbar_active == false then
+    if P.scrollbar_active == false then
         -- brightness
         logMessage(0, "event: brightness")
@@ -148,5 +148,5 @@
 
 function P.GraphicsBrightnessScrollbar_started(e)
-    scrollbar_active = true
+    P.scrollbar_active = true
 end
 
@@ -154,30 +154,30 @@
     -- brightness
     logMessage(0, "event: brightness")
-    scrollbar_active = false
+    P.scrollbar_active = false
 end
 
 function P.GraphicsFullscreenCheckbox_clicked(e)
-    if block == false then
-        search_mode = 0
-        f = io.open(file, "r")
-        firstline = f:read("*line")
-        text = firstline .. "\n"
-        rendersystem = string.sub(firstline, 15)
+    if P.block == false then
+        P.search_mode = 0
+        local f = io.open(P.file, "r")
+        local firstline = f:read("*line")
+        local text = firstline .. "\n"
+        local rendersystem = string.sub(firstline, 15)
         for line in f:lines() do
-            if search_mode == 0 then
+            if P.search_mode == 0 then
                 if string.find(line, rendersystem) ~= nil then
-                    search_mode = 1
+                    P.search_mode = 1
                 end
             end
-            if search_mode == 1 then
+            if P.search_mode == 1 then
                 if string.sub(line, 1, 11) == "Full Screen" then
-                    if fullscreen == true then
+                    if P.fullscreen == true then
                         line = "Full Screen=No"
-                        fullscreen = false
+                        P.fullscreen = false
                     else
                         line = "Full Screen=Yes"
-                        fullscreen = true
+                        P.fullscreen = true
                     end
-                    search_mode = 2
+                    P.search_mode = 2
                 end
             end
@@ -185,5 +185,5 @@
         end
         f:close()
-        f = io.open(file, "w")
+        f = io.open(P.file, "w")
         f:write(text)
         f:close()
Index: code/branches/gamestates3/data/gui/scripts/HUDSheet.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/HUDSheet.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/HUDSheet.lua	(revision 6773)
Index: code/branches/gamestates3/data/gui/scripts/InfoPopup.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/InfoPopup.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/InfoPopup.lua	(revision 6773)
@@ -18,5 +18,5 @@
 
 function P.setCloseButton(closeButton)
-    close = winMgr:getWindow("orxonox/InfoPopup_close")
+    local close = winMgr:getWindow("orxonox/InfoPopup_close")
     close:setVisible(closeButton)
     if(not closeButton) then
Index: code/branches/gamestates3/data/gui/scripts/KeyBindMenu.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/KeyBindMenu.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/KeyBindMenu.lua	(revision 6773)
@@ -6,83 +6,83 @@
 function P.onLoad()
 
-    commandList = {}
-    table.insert(commandList, "fire 0")
-    table.insert(commandList, "fire 1 | unfire")
-    table.insert(commandList, "onpress fire 2")
-    table.insert(commandList, "scale 1 moveFrontBack")
-    table.insert(commandList, "scale -1 moveFrontBack")
-    table.insert(commandList, "boost")
-    table.insert(commandList, "scale 1 moveRightLeft")
-    table.insert(commandList, "scale -1 moveRightLeft")
-    table.insert(commandList, "scale 1 moveUpDown")
-    table.insert(commandList, "scale -1 moveUpDown")
-    table.insert(commandList, "scale -1 rotateRoll")
-    table.insert(commandList, "scale 1 rotateRoll")
-    table.insert(commandList, "scale 1 rotateYaw")
-    table.insert(commandList, "scale -1 rotateYaw")
-    table.insert(commandList, "scale 1 rotatePitch")
-    table.insert(commandList, "scale -1 rotatePitch")
-    table.insert(commandList, "NewHumanController changeMode")
-    table.insert(commandList, "switchCamera")
-    table.insert(commandList, "openConsole")
-    table.insert(commandList, "OverlayGroup toggleVisibility Debug")
-    table.insert(commandList, "OverlayGroup toggleVisibility Stats")
-    table.insert(commandList, "mouseLook")
-    table.insert(commandList, "pause")
-
-    nameList = {}
-    table.insert(nameList, "Primary Fire")
-    table.insert(nameList, "Secondary Fire")
-    table.insert(nameList, "Fire Rocket")
-    table.insert(nameList, "Accelerate")
-    table.insert(nameList, "Break")
-    table.insert(nameList, "Boost")
-    table.insert(nameList, "Move Right")
-    table.insert(nameList, "Move Left")
-    table.insert(nameList, "Move Up")
-    table.insert(nameList, "Move Down")
-    table.insert(nameList, "Roll Right")
-    table.insert(nameList, "Roll Left")
-    table.insert(nameList, "Yaw Left")
-    table.insert(nameList, "Yaw Right")
-    table.insert(nameList, "Pitch Up")
-    table.insert(nameList, "Pitch Down")
-    table.insert(nameList, "Switch Input Mode")
-    table.insert(nameList, "Switch Camera")
-    table.insert(nameList, "Open Console")
-    table.insert(nameList, "Show Debug")
-    table.insert(nameList, "Show Stats")
-    table.insert(nameList, "Look Around")
-    table.insert(nameList, "Pause")
-
-    linesList = {}
+    P.commandList = {}
+    table.insert(P.commandList, "fire 0")
+    table.insert(P.commandList, "fire 1 | unfire")
+    table.insert(P.commandList, "onpress fire 2")
+    table.insert(P.commandList, "scale 1 moveFrontBack")
+    table.insert(P.commandList, "scale -1 moveFrontBack")
+    table.insert(P.commandList, "boost")
+    table.insert(P.commandList, "scale 1 moveRightLeft")
+    table.insert(P.commandList, "scale -1 moveRightLeft")
+    table.insert(P.commandList, "scale 1 moveUpDown")
+    table.insert(P.commandList, "scale -1 moveUpDown")
+    table.insert(P.commandList, "scale -1 rotateRoll")
+    table.insert(P.commandList, "scale 1 rotateRoll")
+    table.insert(P.commandList, "scale 1 rotateYaw")
+    table.insert(P.commandList, "scale -1 rotateYaw")
+    table.insert(P.commandList, "scale 1 rotatePitch")
+    table.insert(P.commandList, "scale -1 rotatePitch")
+    table.insert(P.commandList, "NewHumanController changeMode")
+    table.insert(P.commandList, "switchCamera")
+    table.insert(P.commandList, "openConsole")
+    table.insert(P.commandList, "OverlayGroup toggleVisibility Debug")
+    table.insert(P.commandList, "OverlayGroup toggleVisibility Stats")
+    table.insert(P.commandList, "mouseLook")
+    table.insert(P.commandList, "pause")
+
+    P.nameList = {}
+    table.insert(P.nameList, "Primary Fire")
+    table.insert(P.nameList, "Secondary Fire")
+    table.insert(P.nameList, "Fire Rocket")
+    table.insert(P.nameList, "Accelerate")
+    table.insert(P.nameList, "Break")
+    table.insert(P.nameList, "Boost")
+    table.insert(P.nameList, "Move Right")
+    table.insert(P.nameList, "Move Left")
+    table.insert(P.nameList, "Move Up")
+    table.insert(P.nameList, "Move Down")
+    table.insert(P.nameList, "Roll Right")
+    table.insert(P.nameList, "Roll Left")
+    table.insert(P.nameList, "Yaw Left")
+    table.insert(P.nameList, "Yaw Right")
+    table.insert(P.nameList, "Pitch Up")
+    table.insert(P.nameList, "Pitch Down")
+    table.insert(P.nameList, "Switch Input Mode")
+    table.insert(P.nameList, "Switch Camera")
+    table.insert(P.nameList, "Open Console")
+    table.insert(P.nameList, "Show Debug")
+    table.insert(P.nameList, "Show Stats")
+    table.insert(P.nameList, "Look Around")
+    table.insert(P.nameList, "Pause")
+
+    P.linesList = {}
 
     --Calculate design parameters:
-    sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/KeyBindPane/SampleWindow")
-    sampleWindow:setText("SampleText")
-
-    local size = getMinTextSize(sampleWindow)
-    lineHeight = size[1]
-
-    commandWidth = 0
-    for k,v in pairs(commandList) do
-        sampleWindow:setText(nameList[k])
-        size = getMinTextSize(sampleWindow)
-        if size[2] > commandWidth then
-            commandWidth = size[2]
+    P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/KeyBindPane/SampleWindow")
+    P.sampleWindow:setText("SampleText")
+
+    local size = getMinTextSize(P.sampleWindow)
+    P.lineHeight = size[1]
+
+    P.commandWidth = 0
+    for k,v in pairs(P.commandList) do
+        P.sampleWindow:setText(P.nameList[k])
+        size = getMinTextSize(P.sampleWindow)
+        if size[2] > P.commandWidth then
+            P.commandWidth = size[2]
         end
     end
 
-    sampleWindow:setText("add")
-    size = getMinTextSize(sampleWindow)
-    addWidth = size[2]
-
-    sampleWindow:setText("X")
-    size = getMinTextSize(sampleWindow)
-    clearWidth = size[2]
-
-    spaceWidth = math.floor(1/14*commandWidth)
-
-    buttonWidth = 145
+    P.sampleWindow:setText("add")
+    size = getMinTextSize(P.sampleWindow)
+    P.addWidth = size[2]
+
+    P.sampleWindow:setText("X")
+    size = getMinTextSize(P.sampleWindow)
+    P.clearWidth = size[2]
+
+    P.spaceWidth = math.floor(1/14*P.commandWidth)
+
+    P.buttonWidth = 145
 
     P.createLines()
@@ -113,30 +113,30 @@
     local offset = 0
     local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
-    line:setHeight(CEGUI.UDim(0, lineHeight))
-    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
+    line:setHeight(CEGUI.UDim(0, P.lineHeight))
+    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
 
     local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
-    command:setText(nameList[k])
-    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, commandWidth), CEGUI.UDim(1, 0)))
+    command:setText(P.nameList[k])
+    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
     command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
     line:addChildWindow(command)
-    offset = offset + commandWidth + spaceWidth
+    offset = offset + P.commandWidth + P.spaceWidth
 
     local plus = winMgr:createWindow("MenuWidgets/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus")
-    plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, addWidth), CEGUI.UDim(0.7, 0)))
+    plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.addWidth), CEGUI.UDim(0.7, 0)))
     plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
     plus:setText("add")
     orxonox.GUIManager:subscribeEventHelper(plus, "Clicked", P.name .. ".KeyBindPlus_clicked")
     line:addChildWindow(plus)
-    offset = offset + addWidth + spaceWidth
-
-    local numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
+    offset = offset + P.addWidth + P.spaceWidth
+
+    local numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(P.commandList[k]);
     for i=0,(numButtons-1) do
         local button = winMgr:createWindow("MenuWidgets/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
-        local name = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)
+        local name = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(P.commandList[k],i)
         name = P.KeyNameNiceifier(name)
         button:setText(name)
-        sampleWindow:setText(name)
-        local size = getMinTextSize(sampleWindow)
+        P.sampleWindow:setText(name)
+        local size = getMinTextSize(P.sampleWindow)
         local buttonWidth = size[2]
         button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
@@ -148,13 +148,13 @@
 
         local clear = winMgr:createWindow("MenuWidgets/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i)
-        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.7, 0)))
+        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.clearWidth), CEGUI.UDim(0.7, 0)))
         clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
         clear:setText("X")
         orxonox.GUIManager:subscribeEventHelper(clear, "Clicked", P.name .. ".KeyBindClear_clicked")
         line:addChildWindow(clear)
-        offset = offset + clearWidth + spaceWidth
-    end
-
-    line:setWidth(CEGUI.UDim(0, offset+clearWidth))
+        offset = offset + P.clearWidth + P.spaceWidth
+    end
+
+    line:setWidth(CEGUI.UDim(0, offset+P.clearWidth))
 
     return line
@@ -164,11 +164,11 @@
     local window = winMgr:getWindow("orxonox/KeyBindPane")
 
-    for k,v in pairs(commandList) do
+    for k,v in pairs(P.commandList) do
         local line = P.createLine(k)
-        table.insert(linesList, line)
+        table.insert(P.linesList, line)
         window:addChildWindow(line)
     end
 
-    pane = tolua.cast(window, "CEGUI::ScrollablePane")
+    local pane = tolua.cast(window, "CEGUI::ScrollablePane")
     pane:setVerticalStepSize(getScrollingStepSize(window))
 end
@@ -208,5 +208,5 @@
     local buttonNr = tonumber(match())
 
-    local str = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr)
+    local str = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(P.commandList[commandNr], buttonNr)
     orxonox.KeyBinderManager:getInstance():unbind(str)
 
@@ -218,9 +218,9 @@
     local buttonNr = arguments[2]
     if buttonNr ~= nil then
-        local str = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr)
+        local str = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(P.commandList[commandNr], buttonNr)
         orxonox.KeyBinderManager:getInstance():unbind(str)
     end
 
-    orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr])
+    orxonox.KeyBinderManager:getInstance():keybind(P.commandList[commandNr])
 end
 
@@ -228,12 +228,12 @@
     local pane = tolua.cast(winMgr:getWindow("orxonox/KeyBindPane"), "CEGUI::ScrollablePane")
     local position = pane:getVerticalScrollPosition()
-    while table.getn(linesList) ~= 0 do
-        if linesList[1] ~= nil then
-            winMgr:destroyWindow(linesList[1]:getName())
+    while table.getn(P.linesList) ~= 0 do
+        if P.linesList[1] ~= nil then
+            winMgr:destroyWindow(P.linesList[1]:getName())
         end
-        table.remove(linesList, 1)
-    end
-
-    linesList = {}
+        table.remove(P.linesList, 1)
+    end
+
+    P.linesList = {}
 
     P.createLines()
Index: code/branches/gamestates3/data/gui/scripts/MenuSheet.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/MenuSheet.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/MenuSheet.lua	(revision 6773)
@@ -11,9 +11,9 @@
 -- Parameters:
 -- Except for _name, you can provide nil. Then the default value will be used.
--- For _tShowCusor and _tUseKeyboard you can specify TriBool.Dontcare if the value doesn't matter at all. Then the value of the underlaying sheet will be used.
+-- For _tShowCursor and _tUseKeyboard you can specify TriBool.Dontcare if the value doesn't matter at all. Then the value of the underlaying sheet will be used.
 function P.new(_name, _bHidePrevious, _tShowCursor, _tUseKeyboard, _bBlockJoyStick)
     local newSheet = GUISheet.new(_name)
     newSheet.bHidePrevious  = handleDefArg(_bHidePrevious,  true)
-    newSheet.tShowCursor    = handleDefArg(_tShowCusor,     TriBool.True)
+    newSheet.tShowCursor    = handleDefArg(_tShowCursor,    TriBool.True)
     newSheet.tUseKeyboard   = handleDefArg(_tUseKeyboard,   TriBool.Dontcare)
     newSheet.bBlockJoyStick = handleDefArg(_bBlockJoyStick, false)
Index: code/branches/gamestates3/data/gui/scripts/MouseControlsMenu.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/MouseControlsMenu.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/MouseControlsMenu.lua	(revision 6773)
@@ -4,26 +4,27 @@
 
 function P.onLoad()
-    block = false
-    mousenormalscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MouseNormalScrollbar"),"CEGUI::Scrollbar")
-    mousederivescrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MouseDeriveScrollbar"),"CEGUI::Scrollbar")
-    normalwindow = tolua.cast(winMgr:getWindow("orxonox/MouseNormalButton"),"CEGUI::RadioButton")
-    derivewindow = tolua.cast(winMgr:getWindow("orxonox/MouseDeriveButton"),"CEGUI::RadioButton")
-    invertwindow = tolua.cast(winMgr:getWindow("orxonox/MouseInvertCheckbox"),"CEGUI::Checkbox")
-    mousenormalscrollbar_active = false
-    mousederivescrollbar_active = false
-    derive_active = orxonox.getConfig("KeyBinder","bDeriveMouseInput_")
-    invert_active = false
-    mousenormalsensitivity = orxonox.getConfig("KeyBinder","mouseSensitivity_")
-    mousederivesensitivity = orxonox.getConfig("KeyBinder","mouseSensitivityDerived_")
-    mousenormalscrollbarwindow:setScrollPosition((math.log(14*mousenormalsensitivity-6))/(6*math.log(2)))
-    mousederivescrollbarwindow:setScrollPosition((math.log(14*mousederivesensitivity-6))/(6*math.log(2)))
+    P.block = false
+    P.mousenormalscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MouseNormalScrollbar"),"CEGUI::Scrollbar")
+    P.mousederivescrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MouseDeriveScrollbar"),"CEGUI::Scrollbar")
+    P.normalwindow = tolua.cast(winMgr:getWindow("orxonox/MouseNormalButton"),"CEGUI::RadioButton")
+    P.derivewindow = tolua.cast(winMgr:getWindow("orxonox/MouseDeriveButton"),"CEGUI::RadioButton")
+    --P.invertwindow = tolua.cast(winMgr:getWindow("orxonox/MouseInvertCheckbox"),"CEGUI::Checkbox")
+    P.mousenormalscrollbar_active = false
+    P.mousederivescrollbar_active = false
+    local derive_active = orxonox.getConfig("KeyBinder","bDeriveMouseInput_")
+    local invert_active = false
+    local normal_active
+    P.mousenormalsensitivity = orxonox.getConfig("KeyBinder","mouseSensitivity_")
+    P.mousederivesensitivity = orxonox.getConfig("KeyBinder","mouseSensitivityDerived_")
+    P.mousenormalscrollbarwindow:setScrollPosition((math.log(14*P.mousenormalsensitivity-6))/(6*math.log(2)))
+    P.mousederivescrollbarwindow:setScrollPosition((math.log(14*P.mousederivesensitivity-6))/(6*math.log(2)))
     if derive_active == "true" then
         normal_active = false
         derive_active = true
-        derivewindow:setSelected(derive_active)
+        P.derivewindow:setSelected(derive_active)
     else
         normal_active = true
         derive_active = false
-        normalwindow:setSelected(normal_active)
+        P.normalwindow:setSelected(normal_active)
     end
     if invert_active == "true" then
@@ -35,46 +36,46 @@
 
 function P.MouseControlsMouseNormalScrollbar_changed(e)
-    if mousenormalscrollbar_active == false then
-        scrollposition = mousenormalscrollbarwindow:getScrollPosition()
-        mousenormalsensitivity = (math.pow(64,scrollposition)+6)/14
-        orxonox.config("KeyBinder", "mouseSensitivity_", mousenormalsensitivity)
+    if P.mousenormalscrollbar_active == false then
+        local scrollposition = P.mousenormalscrollbarwindow:getScrollPosition()
+        P.mousenormalsensitivity = (math.pow(64,scrollposition)+6)/14
+        orxonox.config("KeyBinder", "mouseSensitivity_", P.mousenormalsensitivity)
     end
 end
 
 function P.MouseControlsMouseNormalScrollbar_started(e)
-    mousenormalscrollbar_active = true
+    P.mousenormalscrollbar_active = true
 end
 
 function P.MouseControlsMouseNormalScrollbar_ended(e)
-    scrollposition = mousenormalscrollbarwindow:getScrollPosition()
-    mousenormalsensitivity = (math.pow(64,scrollposition)+6)/14
-    orxonox.config("KeyBinder", "mouseSensitivity_", mousenormalsensitivity)
-    mousenormalscrollbar_active = false
+    local scrollposition = P.mousenormalscrollbarwindow:getScrollPosition()
+    P.mousenormalsensitivity = (math.pow(64,scrollposition)+6)/14
+    orxonox.config("KeyBinder", "mouseSensitivity_", P.mousenormalsensitivity)
+    P.mousenormalscrollbar_active = false
 end
 
 function P.MouseControlsMouseDeriveScrollbar_changed(e)
-    if mousederivescrollbar_active == false then
-        scrollposition = mousederivescrollbarwindow:getScrollPosition()
-        mousederivesensitivity = (math.pow(64,scrollposition)+6)/14
-        orxonox.config("KeyBinder", "mouseSensitivityDerived_", mousederivesensitivity)
+    if P.mousederivescrollbar_active == false then
+        local scrollposition = P.mousederivescrollbarwindow:getScrollPosition()
+        P.mousederivesensitivity = (math.pow(64,scrollposition)+6)/14
+        orxonox.config("KeyBinder", "mouseSensitivityDerived_", P.mousederivesensitivity)
     end
 end
 
 function P.MouseControlsMouseDeriveScrollbar_started(e)
-    mousederivescrollbar_active = true
+    P.mousederivescrollbar_active = true
 end
 
 function P.MouseControlsMouseDeriveScrollbar_ended(e)
-    scrollposition = mousederivescrollbarwindow:getScrollPosition()
-    mousederivesensitivity = (math.pow(64,scrollposition)+6)/14
-    orxonox.config("KeyBinder", "mouseSensitivityDerived_", mousederivesensitivity)
-    mousederivescrollbar_active = false
+    local scrollposition = P.mousederivescrollbarwindow:getScrollPosition()
+    P.mousederivesensitivity = (math.pow(64,scrollposition)+6)/14
+    orxonox.config("KeyBinder", "mouseSensitivityDerived_", P.mousederivesensitivity)
+    P.mousederivescrollbar_active = false
 end
 
 function P.MouseNormalButton_clicked(e)
-    if block == false then
-        block = true
-        derivewindow:setSelected(false)
-        block = false
+    if P.block == false then
+        P.block = true
+        P.derivewindow:setSelected(false)
+        P.block = false
         orxonox.config("KeyBinder", "bDeriveMouseInput_", 0)
     end
@@ -82,8 +83,8 @@
 
 function P.MouseDeriveButton_clicked(e)
-    if block == false then
-        block = true
-        normalwindow:setSelected(false)
-        block = false
+    if P.block == false then
+        P.block = true
+        P.normalwindow:setSelected(false)
+        P.block = false
         orxonox.config("KeyBinder", "bDeriveMouseInput_", 1)
     end
Index: code/branches/gamestates3/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/MultiplayerMenu.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/MultiplayerMenu.lua	(revision 6773)
@@ -4,6 +4,6 @@
 
 function P.onLoad()
-    listbox = winMgr:getWindow("orxonox/MultiplayerLevelListbox")
-    preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
+    local listbox = winMgr:getWindow("orxonox/MultiplayerLevelListbox")
+    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
     orxonox.LevelManager:getInstance():compileAvailableLevelList()
     local levelList = {}
@@ -20,5 +20,5 @@
     table.sort(levelList)
     for k,v in pairs(levelList) do
-        item = CEGUI.createListboxTextItem(v)
+        local item = CEGUI.createListboxTextItem(v)
         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
         CEGUI.toListbox(listbox):addItem(item)
@@ -27,18 +27,18 @@
         end
     end
-    local multiplayerMode = "startClient"
-    if multiplayerMode == "startClient" then
-        window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
-        button = tolua.cast(window,"CEGUI::RadioButton")
+    P.multiplayerMode = "startClient"
+    if P.multiplayerMode == "startClient" then
+        local window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
         button:setSelected(true)
     end
-    if multiplayerMode == "startServer" then
-        window = winMgr:getWindow("orxonox/MultiplayerHostButton")
-        button = tolua.cast(window,"CEGUI::RadioButton")
+    if P.multiplayerMode == "startServer" then
+        local window = winMgr:getWindow("orxonox/MultiplayerHostButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
         button:setSelected(true)
     end
-    if multiplayerMode == "startDedicated" then
-        window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
-        button = tolua.cast(window,"CEGUI::RadioButton")
+    if P.multiplayerMode == "startDedicated" then
+        local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
+        local button = tolua.cast(window,"CEGUI::RadioButton")
         button:setSelected(true)
     end
@@ -46,13 +46,13 @@
 
 function P.MultiplayerJoinButton_clicked(e)
-    multiplayerMode = "startClient"
+    P.multiplayerMode = "startClient"
 end
 
 function P.MultiplayerHostButton_clicked(e)
-    multiplayerMode = "startServer"
+    P.multiplayerMode = "startServer"
 end
 
 function P.MultiplayerDedicatedButton_clicked(e)
-    multiplayerMode = "startDedicated"
+    P.multiplayerMode = "startDedicated"
 end
 
@@ -61,5 +61,5 @@
     if choice then
         orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
-        orxonox.execute(multiplayerMode)
+        orxonox.execute(P.multiplayerMode)
         hideAllMenuSheets()
     end
Index: code/branches/gamestates3/data/gui/scripts/PickupInventory.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/PickupInventory.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/PickupInventory.lua	(revision 6773)
@@ -8,5 +8,4 @@
 
 function P.onLoad()
-    carrierList = {}
 end
 
Index: code/branches/gamestates3/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- code/branches/gamestates3/data/gui/scripts/SingleplayerMenu.lua	(revision 6772)
+++ code/branches/gamestates3/data/gui/scripts/SingleplayerMenu.lua	(revision 6773)
@@ -4,6 +4,6 @@
 
 function P.onLoad()
-    listbox = winMgr:getWindow("orxonox/SingleplayerLevelListbox")
-    preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
+    local listbox = winMgr:getWindow("orxonox/SingleplayerLevelListbox")
+    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
     orxonox.LevelManager:getInstance():compileAvailableLevelList()
     local levelList = {}
@@ -20,5 +20,5 @@
     table.sort(levelList)
     for k,v in pairs(levelList) do
-        item = CEGUI.createListboxTextItem(v)
+        local item = CEGUI.createListboxTextItem(v)
         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
         CEGUI.toListbox(listbox):addItem(item)
Index: code/branches/gamestates3/data/lua/LuaStateInit.lua
===================================================================
--- code/branches/gamestates3/data/lua/LuaStateInit.lua	(revision 6772)
+++ code/branches/gamestates3/data/lua/LuaStateInit.lua	(revision 6773)
@@ -1,12 +1,14 @@
--- Note: luaState is a pointer to the LuaState instance that created this lua state
+-- LuaStateInit.lua
+
+-- Note: 'luaState' is a pointer to the LuaState instance that created this lua state
 
 -- Redirect print to the C++ print function
 original_print = print
-print = function(s)
+function print(s)
   luaState:luaPrint(s)
 end
 
 -- Create function to log text like COUT, but always prints a line!
-logMessage = function(level, message)
+function logMessage(level, message)
   luaState:luaLog(level, message)
 end
@@ -15,5 +17,5 @@
 -- Redirect dofile in order to load with the resource manager
 original_dofile = dofile
-dofile = function(filename)
+function dofile(filename)
   if not luaState:doFile(filename) then
     error("Error propagation. Do not display")
@@ -26,5 +28,5 @@
 -- Create includeFile function that preparses the file according
 -- to a function provided to the LuaState constructor (in C++)
-include = function(filename)
+function include(filename)
   if not luaState:includeFile(filename) then
     error("Error propagation. Do not display")
@@ -37,18 +39,12 @@
 -- The loaded modules are then stored with their names (where name has no .lua extension)
 -- Furthermore the ".lua" extension is appended to the moduleName parameter when looking for the file
+_LOADED = {}
+_LOADED_RETURN_VALUES = {}
+_REQUIREDNAME = nil
 original_require = require
-_REQUIREDNAME = ""
-LuaStateReturnValue = true
-require = function(moduleName)
+function require(moduleName)
   if not luaState:fileExists(moduleName .. ".lua") then
     logMessage(2, "Warning: Lua function require() could not find file '" .. moduleName .. ".lua' ")
     return nil
-  end
-
-  if not _LOADED then
-    _LOADED = {}
-  end
-  if not _LOADED_RETURN_VALUES then
-      _LOADED_RETURN_VALUES = {}
   end
 
@@ -69,12 +65,9 @@
     _REQUIREDNAME = _REQUIREDNAME_OLD
   end
-  local asdf = _LOADED_RETURN_VALUES[moduleName]
-  return asdf
+  return _LOADED_RETURN_VALUES[moduleName]
 end
-
 
 -- Load useful tool functions (like handleDefaultArgument)
 require("Tools")
-
 
 -- Include command line debugger for lua 5.1
@@ -84,5 +77,5 @@
 else
   -- Fallback pause function
-  pause = function()
+  function pause()
     logMessage(2, [["Warning: debug() called in Lua, but Debugger is not active.
 Do you have the IOConsole disabled and are you using Lua version 5.1?"]])
@@ -91,5 +84,5 @@
 
 -- General error handler that gets called whenever an error happens at runtime
-errorHandler = function(err)
+function errorHandler(err)
   if type(err) == "string" then
     -- Simply return if the error has already been handled
@@ -112,5 +105,4 @@
 end
 
-
 -- Convenience function for console commands
 orxonox.execute = function(command)
