



Moderators: Víctor Paredes, Belgarath, slowtiger
Code: Select all
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "SF_ImportDat"
-- **************************************************
-- General information about this script
-- **************************************************
SF_ImportDat = {}
function SF_ImportDat:Name()
return "ImportDAT"
end
function SF_ImportDat:Version()
return "1.01"
end
function SF_ImportDat:Description()
return "Import .DAT switch data at current frame"
end
function SF_ImportDat:Creator()
return "Brian Quinn (C) 2005"
end
function SF_ImportDat:UILabel()
return("ImportDAT")
end
--Copyright 2005 Brian Quinn
--released under the Gnu Public License (www.gnu.org)
--all applicable rights reserved.
--updated 8:04pm EDT 4/16/2005
--Thanks to Mike Clifton and Lost Marble. You rock.
-- **************************************************
-- The guts of this script
-- **************************************************
function SF_ImportDat:IsEnabled(moho)
if (moho.layer:LayerType() ~= MOHO.LT_SWITCH) then
return false
end
return true
end
function SF_ImportDat:Run(moho)
local path = LM.GUI.OpenFile("Select .DAT File")
if (path == "") then
return
end
local DATfile = io.open(path, "r")
if (DATfile == nil) then
LM.GUI.Alert(LM.GUI.ALERT_WARNING, "Can't open file", nil, nil, "OK", nil, nil)
return
end
local DATline = ""
DATline = DATfile:read("*line")
if DATline ~= "MohoSwitch1" then
LM.GUI.Alert(LM.GUI.ALERT_WARNING, "Not a proper Switch Data file!", nil, nil, "EXIT", nil, nil)
return
end
local sLayer = moho.layer
local done = false
curFrame = moho.frame
while not done do
DATframe = DATfile:read("*number")
if DATframe then
DATline = DATfile:read("*line")
local stripped = false
while not stripped do
local maybeSpace = string.sub(DATline, 1,1)
if maybeSpace == " " then
DATline = string.sub(DATline, 2)
else
stripped = true
end
end
sLayer:SetValue(DATframe + curFrame, DATline)
print (DATframe + curFrame, DATline, string.len(DATline))
else
done = true
end
end
end
Code: Select all
sLayer:SetValue(DATframe + curFrame, DATline)
Code: Select all
sLayer:InsertAction(DATframe + curFrame, DATline)