Data Realms Fan Forums
http://45.55.195.193/

Help with LUA
http://45.55.195.193/viewtopic.php?f=73&t=23700
Page 1 of 1

Author:  Neutrality [ Thu May 12, 2011 5:43 am ]
Post subject:  Help with LUA

This is probably just a noob problem as I am very inexperienced with lua, what I'm trying to do is make an actor that gibs when it gets a certain distance to an enemy actor.
Code:
function Update(self)
   for actor in MovableMan.Actors do
      local distcheck = SceneMan:shortestDistance(self.Pos,actor.Pos,true).Magnitude
      if distcheck < 20 then
         self.ignoreteam = actor.Team
         self:GibThis()
         break
      end
   end
end

I'm just getting silent crashes when CC loads my .rte, can anyone help with this?

Author:  Roast Veg [ Thu May 12, 2011 4:26 pm ]
Post subject:  Re: Help with LUA

Lua does not cause silent crashes on startup as a general rule, but I can correct some errors for you.
Code:
function Update(self)
   for actor in MovableMan.Actors do
      local distcheck = SceneMan:shortestDistance(self.Pos,actor.Pos,true);
      if distcheck <= 20 then
         self.ignoreteam = actor.Team;
         self:GibThis()
         break
      end
   end
end

Author:  Grif [ Thu May 12, 2011 4:52 pm ]
Post subject:  Re: Help with LUA

Roast Veg wrote:
Lua does not cause silent crashes on startup as a general rule, but I can correct some errors for you.
Code:
function Update(self)
   if self.timer then
   if self.timer:IsPastSimMS(500) then
   self.timer:Reset();
      for actor in MovableMan.Actors do
         local distcheck = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
         if distcheck.Magnitude <= 20 and self.Team ~= actor.Team then
            self:GibThis();
            break;
         end
      end
   else
      self.timer = Timer();
   end
end


FTFY
the timer code will make the game not lag so horrendously; looping through all actors every frame is terribly inefficient.

Author:  zalo [ Thu May 12, 2011 6:24 pm ]
Post subject:  Re: Help with LUA

To fix the silent startup crashes, you'll probably want to try
grafting the Lua script onto a default actor and seeing if that works.

If it does, then your problem is in your actor's .ini code.

If it doesn't, check to make sure your "ScriptFile" leads to the proper location.

Author:  Asklar [ Fri May 13, 2011 2:59 am ]
Post subject:  Re: Help with LUA

Wasn't it ScriptPath?

Author:  Neutrality [ Fri May 13, 2011 4:23 am ]
Post subject:  Re: Help with LUA

It was the code causing the crashes, the script path was fine, problem now is: it loads fine, doesnt work and the console says error 'end' expected at line 16 'eof' even though there is an end at the eof...

Author:  Asklar [ Fri May 13, 2011 4:29 am ]
Post subject:  Re: Help with LUA

That means that you have to add another end.
If that doesn't work, remove the end.

Author:  Neutrality [ Fri May 13, 2011 4:38 am ]
Post subject:  Re: Help with LUA

Well the script loads without any errors now, sadly it doesn't work, any ideas? Thanks for all the help btw.

Author:  Xery [ Fri May 13, 2011 4:55 am ]
Post subject:  Re: Help with LUA

Neutrality wrote:
Well the script loads without any errors now, sadly it doesn't work, any ideas? Thanks for all the help btw.


Code:
self:GibThis();

The script no more runs after its loader disappeared...right?

Author:  Neutrality [ Fri May 13, 2011 5:05 am ]
Post subject:  Re: Help with LUA

I'm not sure what you mean? the script is exactly the same as the code grif posted...

Author:  Xery [ Fri May 13, 2011 5:58 am ]
Post subject:  Re: Help with LUA

Is there any example of this in other mods?

Author:  Neutrality [ Fri May 13, 2011 6:00 am ]
Post subject:  Re: Help with LUA

not sure, it should work just like a landmine of sorts except that its an ahuman actor

Author:  Asklar [ Fri May 13, 2011 8:55 pm ]
Post subject:  Re: Help with LUA

That's wierd.

It's not showing any errors at all?
Could you post the code to check it, please.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/