Help with your scripting

Script won't run??

Script won't run??

Postby Shando » 13 Mar 2013, 22:46

Hi All,

I have made some changes to the "Default" Script to test something out, and now it won't run at all :(

How can I force a Script to run more than once (i.e. when I click the Run button, the Script runs)?

When I import the original "Default" Script everything works fine, but when I import my amended version nothing happens.

Here is my amended Script:

Code: Select all
-- |------------------------------------------------------------------------------------
-- | .: S K Y L I N E :.    Default Lua Script. Script containing some common events         
-- |------------------------------------------------------------------------------------

obj    = 0; -- | Define a global variable for our object ID
count    = 0;

-- |------------------------------------------------------------------------------
-- | initialise
-- |------------------------------------------------------------------------------
function onInit(objID)
   sky.lprint("\nLUA: Welcome - Hello World!");
   obj = objID;
end

-- |------------------------------------------------------------------------------
-- | Update
-- |------------------------------------------------------------------------------
function onUpdate( timeDelta )
   
   -- Do your game loop stuff here....
   --sky.lprint("Counter :: "..count);
   count = count + 1;
end

function onKeyUp( key )
   sky.lprint("Key Released =  "..key);
end

-- |------------------------------------------------------------------------------
-- | Mouse Events
-- |------------------------------------------------------------------------------
function onMouseDown( button, x, y )
   sky.lprint("Mouse Pos x :"..x.."  y : "..y);
   sky.lprint("Mouse Button pressed :"..button);
end

function onMouseUp( button,x ,y )
   sky.lprint("Mouse Button Clicked");
end

function onMouseMove( x, y )
   sky.lprint("MOVING! Pos x :"..x.."  y : "..y);
end

-- |------------------------------------------------------------------------------
-- | Object Clicked: see sky.clickObject() for more information
-- |------------------------------------------------------------------------------
function onClick(  )

end

-- |------------------------------------------------------------------------------
-- | Stop
-- |------------------------------------------------------------------------------
function onStop()

end

function onKeyDown ( key )
   if ( key == "p" ) then
   sky.lprint ( "\nLUA: Hello World!" );
    obj = objID;

   file = io.open("H:/Aurasoft/MapData.csv")

   if file == nil then
      sky.lprint("NO FILE")
   else
      sky.lprint("YES FILE")
   end
   
   loadCSV ( "H:\Aurasoft\MapData.csv" );
   end
end

function readcsv (file)
   local fp = assert(io.open (file))
   local csv = {}
   
   for line in fp:lines() do
      local row = {}

      for value in line:gmatch("[^,]*") do -- note: doesn\'t work with strings that contain , values
         row[#row+1] = value
      end
      
      csv[#csv+1] = row
   end

   -- csv contains now rows / colums from the csv file, i.e.
   return csv
end

function loadCSV ( sCSV )
   local tTab={};
   local aa, bb, cc, dd, ee
   local yy, zz
   
   sky.lprint("In loadCSV")

   tTab = readcsv ( sCSV )
   
   yy = table.getn(tTab)
   
   sky.lprint("" .. yy)
   
   for zz = 0 to yy
      sky.lprint(sLine)

      tTab = fromCSV ( sLine );

      aa = tTab [ 0 ]
      bb = tTab [ 1 ]
      cc = tTab [ 2 ]
      dd = tTab [ 3 ]
      ee = tTab [ 4 ]
      
      sky.lprint ( aa .. " - " )
      sky.lprint ( bb .. " - " )
      sky.lprint ( cc .. " - " )
      sky.lprint ( dd .. " - " )
      sky.lprint ( ee .. "/n" .. "/n" )
   end
end


As usual, any help would be greatly appreciated.

Regards

Shando
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Script won't run??

Postby StarFire » 13 Mar 2013, 23:22

How can I force a Script to run more than once (i.e. when I click the Run button, the Script runs)?

A script has its onInit() event called once the play button is pressed or in a already running scene if you pressed save button in the main script editor.

Generally when a script fails, all of the commands following the failed event stop some times even to a point that the script fails in general. We will at some point add some error system but for now keep an eye on the doc console as many lua errors show up there. Also use the sky.trace() or sky.lprint("") in choice places, then you can use this if the script fails to locate roughly where it failed.

I will have a look at your script and see if I can find out where your error is ;)
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Script won't run??

Postby StarFire » 13 Mar 2013, 23:32

Just had a look and noticed that your for loop is incorrect:

Code: Select all
for zz = 0 to yy
..
..
end


it should look like this:

Code: Select all
for zz=0,yy do
..
..
end


There is a section in the API on how to use basic conditions and loops which may be of help as reference: http://www.chi-ad.com/Skyline/API/Lua/html/class_basic___syntax.html#a8fcda67e120ca94bc1de40878a76d41a

Hope this helps :)
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Script won't run??

Postby Shando » 13 Mar 2013, 23:36

Hi NightHawk,

Thanks for the reply.

Just goes to show I haven't been doing much in the way of Lua coding for a while :oops: ( mostly Z80 machine code the last few months :geek: )

I'll make the change and see if that works.

Regards

Shando

Edit: All good now :D
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Script won't run??

Postby StarFire » 13 Mar 2013, 23:44

not a problem, we are please to hear it is working now =)

It would be good to see your csv code once you get it working ;)
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 7 guests

cron