lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


----- Original Message -----
From: "David Jeske" <jeske@chat.net>
|   2) It's hard for people to write a script object for my
|      game because they have trouble figuring out where they
|      are supposed to put the puntcuation in the table/class
|      declaration. They have to put a comma after each element, and
|      after each "end" of a method, except the last one. Then,
|      they better not forget all the end punctuation in the
|      closing table/function/statement end. i.e. "});"
|      They normally just copy my class, but when it breaks, they
|      don't know which little comma they were missing.

Can you not just alter the layout?
eg.

| ------[ real class example follows:
|
| declare_class("MainShip", {
| _parents = { air_physics, controllable, collidable },
|
| Condition = "Healthy",
| imgdir = 2.0,   -- the image index
|
| rimgdir = 1.0,
| direction = 0.0, -- in degrees
| bullet_type = "bullet",
| objtype = "mainship",
| exp_timer = 0.0,
| frame_time = 70,
| layer = 1,
|
| damage = 0,
| damage_max = 10,
| recharge_rate = 0.1,
|
| VisualRep = VisualReps.newDropShip,
|
| -- dummy ai_event
| ai_event = function(self)
| end,
|
| -- constructor
| new = function (self,a_list) -- constructor
| if (type(a_list) ~= "table") then
| print("mainship:new() called with non-table "..tostring(a_list));
| else
| a_list._parents = { self };
| a_list.key = {}; -- make our private keydown list
| a_list.ctrl_centered = 1.0;
| a_list.dest_dir = 0.0;
| end
| return a_list
| end,
|
| recharge = function (self,byWhom) -- recharge method
| local damage = self.damage;
| if (damage > 0) then
| damage = max(0,damage - recharge_rate);
| self.damage = damage;
| end
| end
| }); -- register done



avoiding those commas... being able to avoid anonymous functions would be nice
however.
Would it be possible to be able to use t={ function a() print("hello") end } in
a table instead of t={ a=function() print(...) end }



function declare_mainship()
  local classinfo = {
    _parents = { air_physics, controllable, collidable },
    Condition = "Healthy",
    imgdir = 2.0,   -- the image index

    rimgdir = 1.0,
    direction = 0.0, -- in degrees
    bullet_type = "bullet",
    objtype = "mainship",
    exp_timer = 0.0,
    frame_time = 70,
    layer = 1,

    damage = 0,
    damage_max = 10,
    recharge_rate = 0.1,

    VisualRep = VisualReps.newDropShip
  }

  -- dummy ai_event
  classinfo.ai_event = function ai_event(self)
  end

  -- constructor
  classinfo.new = function (self,a_list) -- constructor
    if (type(a_list) ~= "table") then
      print("mainship:new() called with non-table "..tostring(a_list));
    else
     a_list._parents = { self };
     a_list.key = {}; -- make our private keydown list
     a_list.ctrl_centered = 1.0;
     a_list.dest_dir = 0.0;
    end
    return a_list
  end

  classinfo.recharge = function (self,byWhom) -- recharge method
    local damage = self.damage;
    if (damage > 0) then
      damage = max(0,damage - recharge_rate);
      self.damage = damage;
    end
  end

  declare_class("MainShip", classinfo)
end