|
Post by snoopie on Feb 16, 2006 21:33:09 GMT -5
ok, i cant get the tonumber() to work. i parse a string and am able to extract teh substring "0.3" in the variable named skillInc and i want to convert this to an actual number so im using the command tonumber(skillInc) but it always returns nill. any suggestions?
|
|
|
Post by X-Drop on Feb 16, 2006 22:24:28 GMT -5
Floats can be tricky. I used this to extract a float in my script,
local _, _, j = string.find( string, "blah blah blah (0%.%d) blah blah blah!" )
Then when I used j in my script, I usually don't bother to use tonumber(), because Lua will automatically convert string and number types to the correct format in order to perform calculations.
Double check the method your using to extract the string. That is probably the issue.
|
|
|
Post by snoopie on Feb 17, 2006 0:07:51 GMT -5
i tried to just to just use the string i got in a calculation buti got this
attempt to perform arithmetic on global skillLvl'(a string value) when skillLvl = 118.
ideas
|
|
|
Post by snoopie on Mar 26, 2006 15:27:33 GMT -5
ok so to circumvent the lunar FFXI libraries being down, im doing some string parsing of the chat window. im having dificulties. here is what i got so far
function getMP() Control.control_SendString("/echo <mp>") Windower.script_Sleep(0700) -- give line time to appear newLineNum = FFXI.chat_GetNewestLineNumber() readLine = FFXI.chat_GetLine(newLineNum) a, b, c, d = string.find(readLine, "(%d%d%d)/(%d%d%d)") return c, d end
currentMP, maxMP = getMP()
my problem is the (%d%d%d) i just happen to know that it is 3 digits. i tried (%.%d) but that didnt work. this code only works about half the time, and when it does work lunar sees currentMP as a string not a number. HELP!!!
|
|
sdphantom
Full Member
Savior and Destroyer
Posts: 230
|
Post by sdphantom on Mar 27, 2006 0:20:50 GMT -5
ok so to circumvent the lunar FFXI libraries being down, im doing some string parsing of the chat window. im having dificulties. here is what i got so far function getMP() Control.control_SendString("/echo <mp>") Windower.script_Sleep(0700) -- give line time to appear newLineNum = FFXI.chat_GetNewestLineNumber() readLine = FFXI.chat_GetLine(newLineNum) a, b, c, d = string.find(readLine, "(%d%d%d)/(%d%d%d)") return c, d end currentMP, maxMP = getMP() my problem is the (%d%d%d) i just happen to know that it is 3 digits. i tried (%.%d) but that didnt work. this code only works about half the time, and when it does work lunar sees currentMP as a string not a number. HELP!!! Try this: a, b, c, d = string.find(readLine,"(%d+)/(%d+)")
|
|
|
Post by snoopie on Mar 27, 2006 7:51:40 GMT -5
excelent, that worked for getting all the digits. now the only prob im having is when i do: while currentMP > 7 do ... end i get "attempt to compare number with string" so it thinks that the value returned from the (%d+) above is a string instead of a number. any ideas?
|
|
|
Post by snoopie on Mar 27, 2006 18:29:49 GMT -5
function getMP() Control.control_SendString("/echo <mp>") Windower.script_Sleep(0700) -- give line time to appear newLineNum = FFXI.chat_GetNewestLineNumber() readLine = FFXI.chat_GetLine(newLineNum) a, b, c, d = string.find(readLine, "(%d%d%d)/(%d%d%d)") return c, d end currentMP, maxMP = getMP() ok i fixed it. i just added cMP = tonumber(c) mMP = tonumber(d) and it reads currentMP and maxMP as numbers now. awsome
|
|
sdphantom
Full Member
Savior and Destroyer
Posts: 230
|
Post by sdphantom on Mar 28, 2006 3:27:24 GMT -5
Ya, it returns the digits, but the varible type is still a string.
|
|
|
Post by snoopie on Mar 28, 2006 6:29:32 GMT -5
the code still only works half the time, the other half it returns nil. dunno why
|
|
|
Post by X-Drop on Mar 28, 2006 10:19:01 GMT -5
the code still only works half the time, the other half it returns nil. dunno why Perhaps because the other half of the time your using string.find on the wrong chat line. Here is a tip, use the windower console to display troubleshooting info like the current chat line, the captured strings from string.find, or even display the data's type( ). This is invaluable for me. function getMP()Control.control_SendString("/echo <mp>") Windower.script_Sleep(0700) -- give line time to appear newLineNum = FFXI.chat_GetNewestLineNumber() readLine = FFXI.chat_GetLine(newLineNum) Windower.console_Write(readLine) -- temp!! a, b, c, d = string.find(readLine, "(%d%d%d)/(%d%d%d)") Windower.console_Write("c = " .. c) -- temp!! Windower.console_Write("d = " .. d) -- temp!! return c, d end
currentMP, maxMP = getMP()
|
|
sdphantom
Full Member
Savior and Destroyer
Posts: 230
|
Post by sdphantom on Mar 28, 2006 15:18:17 GMT -5
Here's some code I use to capture and categorize chat entries by code to help identify what codes go to what types of entries. txtObj=Graphics.text_CreateObject() Graphics.text_SetColor(192,255,255,255,txtObj) Graphics.text_SetFont("Arial Bold",12,txtObj) Graphics.text_SetPosition(5,800,txtObj)
chatPos=FFXI.chat_GetOldestLineNumber() function chatPop() if FFXI.chat_GetNewestLineNumber()>chatPos then chatPos=chatPos+1 return FFXI.chat_GetLineType(chatPos),FFXI.chat_GetLine(chatPos) else return nil,nil end end
posX,posY=5,5
chatCodes={} for i=1,256 do chatCodes={}
chatCodes.disp=Graphics.text_CreateObject() Graphics.text_SetColor(255,255,255,255,chatCodes.disp) Graphics.text_SetFont(fontFace,fontSize,chatCodes.disp) Graphics.text_SetPosition(posX+(math.floor((i-1)/64)*300),posY+(math.mod(i-1,64)*14),chatCodes.disp)
Graphics.text_SetText(string.format("%02x",i-1).."=",chatCodes.disp) Graphics.text_SetText(string.format("Creating Text Objects: %4.2f%%",math.floor((i/256)*100)/100),txtObj) end
while true do local chatCode,chatLine=chatPop()
if chatCode and string.find(chatLine,"%w") then Graphics.text_SetText(chatCode.."="..chatLine,chatCodes[tonumber(chatCode,16)+1].disp) Graphics.text_SetText(chatCode.." = "..chatLine,txtObj) end end
|
|
|