I am using the R4 DS card. I am using DS Lua 0.6 I have trying patching all flavors of the DsLua (Blue, Green, Gray, gbfs) with the DLDI with no success. The DLDI gui always says it can't find any section it can patch in each of the flavors of the DsLua.nds.
When I run any of the DSLua flavors on my ds, I just get an empty black screen. How can I fix this? Thanks in advance!
This is a bit of a cop-out answer, but if you are unsure if your screens are initialized (I assume you mean for text), then you're probably better off just resetting and reinitializing them.
sorry for the double post, but is it possible to completely reset the program (DSLua) internally to flush everything before running the MAIN script again?
I'm not sure if that would cause it to crash but to free global variables from memory you set them to nil.
x = nil
I tried setting all my variables to nil at the end of my program, but it still crashed when I edited a script the second time. An interesting thing I found, though, is that when the screen goes black, it won't reset with Start, like normal scripts, it only resets with Select.
Here's the Source:
My Include file, it contains a function to set up the screens and a function to return a character from a table: -- set up screens for text output function initScrTxt() local SCR_BOT = 0 BGBT = Screen.LoadTextBG() Screen.Initialize(SCR_BOT, BGBT)
local SCR_TOP = 1 BGTT = Screen.LoadTextBG() Screen.Initialize(SCR_TOP, BGTT) end
function getChar() local chars = { {'.','Enter',' ','<','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',')','(','+','-','*','/','1','2','3','4','5','6','7','8','9','0',' ',' ' },{'.','Enter',' ','<','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','}','{','=',',','?','"','!','@','#','$','%','^','&','_',':',';','~','`' } } while true do BGBT:PrintXY(0,4,tostring(shift)) BGBT:PrintXY(0,5,tostring(caps)) if switch == true then BGBT:PrintXY(15,9,'^') BGBT:PrintXY(17,11,'> ') BGBT:PrintXY(15,13,'v') BGBT:PrintXY(13,11,'<') if Pads.A() then while Pads.A() do end return 'save' elseif Pads.Up() then while Pads.Up() do end return 'up' elseif Pads.Right() then while Pads.Right() do end return 'right' elseif Pads.Down() then while Pads.Down() do end return 'down' elseif Pads.Left() then while Pads.Left() do end return 'left' elseif Pads.Select() then while Pads.Select() do end return 'exit' elseif Pads.Start() then while Pads.Start() do end switch = false elseif Pads.L() then while Pads.L() do end return 'first' elseif Pads.R() then while Pads.R() do end return 'last' end else if Pads.Start() then while Pads.Start() do end switch = true elseif Pads.Select() then while Pads.Select() do end temp = caps caps = shift shift = math.abs(shift - 1) shift = shift - temp elseif Pads.Up() then offset = 5 if Pads.Left() then offset = 21 elseif Pads.Right() then offset = 25 end elseif Pads.Right() then offset = 9 if Pads.Down() then offset = 29 end elseif Pads.Down() then offset = 13 if Pads.Left() then offset = 33 end elseif Pads.Left() then offset = 17 elseif Pads.L() then offset = 37 if Pads.R() then offset = 45 end elseif Pads.R() then offset = 41 else offset = 1 end up = chars[shift+caps+1][offset] right = chars[shift+caps+1][offset+1] down = chars[shift+caps+1][offset+2] left = chars[shift+caps+1][offset+3] BGBT:PrintXY(15,9,up) BGBT:PrintXY(17,11,right .. ' ') BGBT:PrintXY(15,13,down) BGBT:PrintXY(13,11,left) if Pads.X() or Pads.A() or Pads.B() or Pads.Y() then shift = shift - shift end if Pads.X() then while Pads.X() do end return up elseif Pads.A() then while Pads.A() do end return right elseif Pads.B() then while Pads.B() do end return down elseif Pads.Y() then while Pads.Y() do end return left end end end end
Here's my actual editing program:
dofile("/SCRIPTS/editlua/include.lua")
function dispFile() BGTT:Clear() local rowtemp = row for i in pairs(filetab) do if i == curline then linescr = rowtemp local linetemp = string.sub(filetab,1,curlet-1) .. '|' .. string.sub(filetab,curlet,-1) BGTT:SetColor(2) BGTT:PrintXY(0,rowtemp,linetemp) BGTT:SetColor(0) else BGTT:PrintXY(0,rowtemp,filetab) end if(string.len(filetab) > 31) then rowtemp = rowtemp + 2 else rowtemp = rowtemp + 1 end end end
initScrTxt()
BGBT:PrintXY(0,0,"Enter file path")
BGTT:PrintXY(0,0,filepath) shift, caps = 0, 0 curline, curlet = 1, 1 linescr = 0 row = 0 switch = false while true do letter=getChar() if letter=="Enter" then break elseif letter == '<' then filepath = string.sub(filepath,1,-2) BGTT:PrintXY(0,0,filepath .. ' ') else filepath = filepath .. letter BGTT:PrintXY(0,0,filepath) end end BGTT:Clear()
file = io.open(filepath,'rt') l = 1 filetab = {} for line in io.lines(filepath) do filetab[l] = line l = l + 1 end
dispFile()
while true do letter = getChar() if letter == 'Enter' then table.insert(filetab,curline + 1,'') parta = string.sub(filetab[curline],1,curlet-1) partb = string.sub(filetab[curline],curlet,-1) filetab[curline] = parta curline = curline + 1 filetab[curline] = partb curlet = 1 elseif letter == 'save' then fout = io.open(filepath,'wt') for i,v in ipairs(filetab) do fout:write(v .. '\n') end fout:close() BGBT:PrintXY(5,5,'Saved') elseif letter=="exit" then break elseif letter == '<' then if filetab[curline] == '' then curtemp = curline - 1 lettemp = string.len(filetab[curtemp]) + 1 table.remove(filetab,curline) curline = curline - 1 curlet = lettemp elseif curlet == 1 then temp = filetab[curline] table.remove(filetab,curline) curline = curline - 1 filetab[curline] = filetab[curline] .. temp curlet = lettemp else filetab[curline] = string.sub(filetab[curline],1,curlet-2) .. string.sub(filetab[curline],curlet,-1) curlet = curlet - 1 end elseif letter == 'left' then if curlet == 1 and curline > 1 then curline = curline - 1 curlet = string.len(filetab[curline]) + 1 else if curlet > 1 then curlet = curlet - 1 end end elseif letter == 'right' then if curlet == string.len(filetab[curline]) + 1 and curline < table.getn(filetab) then curline = curline + 1 curlet = 1 elseif curlet < string.len(filetab[curline])+1 then curlet = curlet + 1 end elseif letter == 'up' then if linescr < 7 and row < 0 then if string.len(filetab[curline-1]) <= 31 then row = row + 1 elseif string.len(filetab[curline-1]) > 31 then row = row + 2 end end if curline > 1 then curline = curline - 1 end if filetab[curline] == '' then curlet = 1 end if curlet >string.len(filetab[curline])+1 then curlet = string.len(filetab[curline]) + 1 end elseif letter == 'down' then if curline < table.getn(filetab) then if linescr > 16 then if string.len(filetab[curline]) <= 31 then row = row - 1 elseif string.len(filetab[curline]) >31 then row = row - 2 end end curline = curline + 1 end if filetab[curline] == '' then curlet = 1 end if curlet >string.len(filetab[curline])+1 then curlet = string.len(filetab[curline]) + 1 end elseif letter == 'first' then curlet = 1 elseif letter == 'last' then curlet = string.len(filetab[curline]) + 1 else filetab[curline] = string.sub(filetab[curline],1,curlet-1) .. letter .. string.sub(filetab[curline],curlet,-1) curlet = curlet + 1 end dispFile() Screen.WaitForVBL() end
for i,v in ipairs(dirs) do dirCount = dirCount + 1 end
for i,v in ipairs(files) do fileCount = fileCount + 1 end end
function stringreverse(str) local reversed = ""; for i = string.len(str), 1, -1 do reversed = reversed..string.sub(str,i,i); end return reversed; end
function dofile (filename) local f = assert(loadfile(filename)) return f() end
firstTime = true
while(true)do if(firstTime)then firstTime = false changeDirectory("/") end if(lastpos == pos)then else lastpos=pos line = pos BGBotText:Clear() BGBotText:SetColor(6) for i,v in ipairs(dirs) do if(line >= 0 and line <= 19)then BGBotText:PrintXY(0,line," " .. v) end line=line+1 end for i,v in ipairs(files) do if(string.lower(string.sub(v, string.len(v)-3)) == ".lua")then BGBotText:SetColor(2) else BGBotText:SetColor(0) end if(line >= 0 and line <= 23)then BGBotText:PrintXY(0,line," " .. v) end line=line+1 end BGBotText:PrintXY(0,0,">") end if(Pads.Down())then while(Pads.Down())do end if(line > 1)then pos = pos-1 end end if(Pads.Up())then while(Pads.Up())do end if(pos < 0)then pos = pos+1 end end aActive = false bActive = false yActive = false if(Pads.A() or Pads.B() or Pads.Y())then while(Pads.A() or Pads.B() or Pads.Y())do if(Pads.A())then aActive = true bActive = false yActive = false elseif(Pads.B())then bActive = true aActive = false yActive = false elseif(Pads.Y())then aActive = false bActive = false yActive = true end end if(aActive and (-pos < dirCount))then for i,v in pairs(dirs) do if(i==-pos+1)then if(v == ".")then elseif(v == "..")then currentDirectory = string.sub(currentDirectory, 1, string.len(currentDirectory) - string.find(stringreverse(currentDirectory), "/")) if(currentDirectory == "")then currentDirectory = "/" end changeDirectory(currentDirectory) else if(currentDirectory == "/")then currentDirectory = currentDirectory .. v else currentDirectory = currentDirectory .. "/" .. v end if(currentDirectory == "")then currentDirectory = "/" end changeDirectory(currentDirectory) break end end end elseif(bActive and (-pos < dirCount))then--fix this to ignore B in root directory currentDirectory = string.sub(currentDirectory, 1, string.len(currentDirectory) - string.find(stringreverse(currentDirectory), "/")) if(currentDirectory == "")then currentDirectory = "/" end changeDirectory(currentDirectory) elseif(aActive)then for i,v in pairs(files) do if(i==-pos-dirCount+1)then if(string.lower(string.sub(v, string.len(v)-3)) == ".lua")then Screen.ResetAll() dofile(v) Screen.ResetAll() BGBotText = Screen.LoadTextBG() Screen.Initialize( SCREEN_BOTTOM, BGBotText ) changeDirectory(currentDirectory) end end end elseif(yActive)then for i,v in pairs(files) do if(i==-pos-dirCount+1)then if(string.lower(string.sub(v, string.len(v)-3)) == ".lua")then Screen.ResetAll() filepath = currentDirectory .. '/' .. v dofile("/SCRIPTS/editlua/editlua.lua") Screen.ResetAll() BGBotText = Screen.LoadTextBG() Screen.Initialize( SCREEN_BOTTOM, BGBotText ) changeDirectory(currentDirectory) end end end end end end
-- wait until a key is pressed DSLua.WaitForAnyKey()