Jump to content

AndyGFX

Members
  • Posts

    124
  • Joined

  • Last visited

Posts posted by AndyGFX

  1. Sample data file [game.lua]:

    
    return
    {
       pos = {0,1,2},
       name = "player1",
       other =
    	{
    		items =
    			{"item1","item1","item1"}
    	}
    
    }
    
    
    

     

     

    call in code:

     

    
    
    GameData = dofile("game.lua")
    
    -- test data
    
    print(GameData.pos[1],GameData.pos[2],GameData.pos[3])
    print(GameData.name)
    print(GameData.other.items[1])
    print(GameData.other.items[2])
    print(GameData.other.items[3])
    
    
    

     

    Note: When your data are static, then is possible compile file to binary format: luac -o game.data game.lua, but then you don't forget change filename in your code, when output filename isn't same.

  2. Here is simple example, howto compile lua scripts into single file (good for distribution) when you can't distribute lua source.

     

    Download: Sample

     

    LUAC command line:

     

    luac -o <output lua filename>.<your extension> <main lua script filename> <additional lua scripts #1> <additional lua scripts #2> ... <additional lua scripts #n>
    

     

    sample:

     

    
    luac -o main_lua.bin main_lua.lua scripts/script1.lua scripts/script3.lua scripts/script2.lua 
    
    

     

    or

     

    
    luac -o main_lua.bin main_lua.lua scripts/*.lua
    
    

     

    Note: don't use script extension with require command.

    • Upvote 1
  3. Other option for loading data to lua from text file, is command dofile, where loaded file has format like this:

     

    file "game.data":

    
    return
    {
       pos = {0,1,2},
       name = "player1",
       other =
    	{
    		items =
    			{"item1","item1","item1"}
    	}
    
    }
    
    
    

     

     

    then in your script call:

     

    GameData = dofile("game.data")
    

     

     

    Chceck data:

     

    
    print(GameData.pos[1],GameData.pos[2],GameData.pos[3])
    print(GameData.name)
    print(GameData.other.items[1])
    print(GameData.other.items[2])
    print(GameData.other.items[3])
    
    

     

    Benefit is, that you don't need write parser for data.

     

    EDIT:

     

    When you need data more secure, then compile your game data file with:

     

    
    luac -o game.cdata game.data
    
    

     

    your data are in binary format now, and simply change loading to GameData = dofile("game.cdata").

     

    Note: Compiled data are good only for static data like startup setting, scene properties, addons, items descr., ...

    • Upvote 1
  4. I have used same code for two emitters, difference is only in parameter CYCLEMODE, but result looks like bug, because Emitter position is moved in Velocity vector too, when is cyclemode set to 1. Is it bug? (From my point of view - yes) but I waiting for confirmation from others. Then i write bug to bugtracker, when yes.

     

    
    Function Fire()
    
    Local particle:TEmitter
    
    setWorld(fw.transparency.world)
    
    	particle = CreateEmitter(80, 500, Vec3(0, 4, 0), 0)
    
    	particle.SetPosition(Vec3(-1, 0, 0))
    	particle.SetRotation(Vec3(0, 0, 0))
    	EntityColor(particle, Vec4(1, 0.5, 0.25, 0.5))
    	PaintEntity(particle, LoadMaterial("abstract::fire.mat"))
    	SetEmitterRadius(particle, 0.1, 0.5)
    	SetEmitterRotationSpeed(particle, 0.2)
    
    setWorld(fw.Main.world)
    
    
    Local particle2:TEmitter
    
    setWorld(fw.transparency.world)
    
    	particle2 = CreateEmitter(80, 500, Vec3(0, 4, 0), 1)
    
    	particle2.SetPosition(Vec3(1, 0, 0))
    	particle2.SetRotation(Vec3(0, 0, 0))
    	EntityColor(particle2, Vec4(1, 0.5, 0.25, 0.5))
    	PaintEntity(particle2, LoadMaterial("abstract::fire.mat"))
    	SetEmitterRadius(particle2, 0.1, 0.5)
    	SetEmitterRotationSpeed(particle2, 0.2)				
    
    setWorld(fw.Main.world)
    
    End Function
    
    

     

    emitter.png

  5. Try this my hint:

     

    - when you press move control, define movement vector for player not from model (Z axis vector), but from camera axis vectors, because camera is always oriented toward screen and looks on level/player from side when we talk about "side scroll" control.

     

    Pseudo math code for movement:

     

    to right/left:

    Pivot_pos = Pivot_pos +/- Camera_X_axis_vetor

     

    to up/down:

    Pivot_pos = Pivot_pos +/- Camera_Z_axis_vetor

     

    with this, player movement always looks like "side scroll", aligned to camera view.

  6. From editor set properties on your model like mass and Collision Type, when property windows is empty - add lua script with name like your model.

     

    Note: Template script is in Scripts folder ("template.lua").

  7. Strictly speaking - each object when is rotated, translated, ... , has oriented toward Z axis vector.

    For example TurnEntity(e,Vec3(0,0,1)) - move entity in Z axis direction.

    Camera works same. Your look direction is Z axis direction, oriented by actual camera/entity rotation.

  8. Globaly this talk, that you have used variable which isn't instance or isn't declared/defined in called script.

     

    Try add:

     

    whatever = {}

     

    when 'whatever' is you variable.

  9. Key codes are not problem, when i execute scene in Editor only with lua code (source is in post #3), then works, message is received and sent to target.

    Strange for me is, why when message is sent from lua code, why isn't received in BMX code too. I don't need make response in lua, i need read this message only in main BMX code.

     

    Main question is, is possible send message in LUA and RECEIVE in BMX code? I have tested SEND/RECEIVE in LUA - works, BMX too. From LUA to BMX doesn't work or i have realy issue.

     

     

    EDIT: Yes, works now. key constans i had included in lua, but BMX don't execute main lua script where I had this one.

    Many thanks.

  10. Entity func_gamecontrol is now linked to this player entity in editor ...

     

    require("scripts/class")
    
    local class=CreateClass(...)
    
    
    function class:InitDialog(grid)
    
    self.super:InitDialog(grid)
    
    end
    
    function class:CreateObject(model)
    
    local object=self.super:CreateObject(model)
    object.model.mass = 1.0
    object.classname = "player_model"
    object.last_message = ""
    object.receive_is_locked = 0
    
    object.step = 0.05
    object.move_step = 0
    object.move_distance = 0
    object.max_distance = 1.0
    
    object.turn = 4.0
    object.turn_step = 0
    object.turn_angle = 0
    object.max_angle = 90
    
    object.local_y_angle=0
    
    object.wheel_left = LoadModel("abstract::player_car_wheel.gmf")
    
    object.wheel_right = LoadModel("abstract::player_car_wheel.gmf")
    
    
    local body_pos = Vec3(0,0,0) --object.model:GetPosition()
    
    local body_wheel_left = Vec3(body_pos.x+0.32,body_pos.y+0.25,body_pos.z)
    local body_wheel_right = Vec3(body_pos.x-0.32,body_pos.y+0.25,body_pos.z)
    
    object.wheel_right:SetPosition(body_wheel_right)
    object.wheel_right:SetParent(object.model)
    
    object.wheel_left:SetPosition(body_wheel_left)
    object.wheel_left:SetParent(object.model)
    
    
    end
    
    

     

    and in BMX now i tried assign callback direct to target entity, which is entity with classname "player_model"

     

    
    'LEVEL CCLASS
    ...
    
    Self.Player.CreatePlayerFromLevel(Level.GetByClassName("func_gamecontrol")) ' <- return scene entity with classname="func_gamecontrol"
    
    ' PLAYER CLASS
    ...
    Method CreatePlayerFromLevel(e:TEntity)
    	Local e_player:TEntity = GetEntityTarget(e, 0)
    	SetEntityCallback(e_player, Byte Ptr MyMessageReceiveCallback, ENTITYCALLBACK_MESSAGERECEIVE)
    End Method
    
    ...	
    
    End Type
    
    
    Function MyMessageReceiveCallback(entity:TEntity, message:String, extra:Object)
    If entity Then
    	Print(message)
    End If
    End Function
    

     

    I tried retype entity e_player to TBody and to TModel too. Alls with same result as before.

  11. Isn't problem ...

     

    Lua script:

     

    require("scripts/class")
    
    local class=CreateClass(...)
    
    
    function class:InitDialog(grid)
    
    self.super:InitDialog(grid)
    
    
    group = grid:AddGroup("Key Binding")
    group:AddProperty("key_forward", PROPERTY_STRING, "","Key Forward")
    group:AddProperty("key_backward", PROPERTY_STRING, "","Key Backward")
    group:AddProperty("key_turn_left", PROPERTY_STRING, "","Key Turn left")
    group:AddProperty("key_turn_right", PROPERTY_STRING, "","Key Turn right")
    
    
    end
    
    function class:CreateObject(model)
    
    local object=self.super:CreateObject(model)
    
    object.classname = "func_gamecontrol"
    
    -- default key binds
    object.key_forward = "KEY_UP"
    object.key_backward = "KEY_DOWN"
    object.key_turn_left = "KEY_LEFT"
    object.key_turn_right = "KEY_RIGHT"
    
    
    function object:SetKey(key,value)
    	if key=="key_forward" then object.key_forward = value
    	elseif key=="key_backward" then object.key_backward = value
    	elseif key=="key_turn_left" then object.key_turn_left = value
    	elseif key=="key_turn_right" then object.key_turn_right = value
    	else
    		return self.super:SetKey(key,value)
    	end
    	return 1
    end
    
    
    
    function object:GetKey(key,value)
    	if key=="key_forward" then return object.key_forward
    	elseif key=="key_backward" then  return object.key_backward
    	elseif key=="key_turn_left" then  return object.key_turn_left
    	elseif key=="key_turn_right" then  return object.key_turn_right
    
    	else
    		return self.super:GetKey(key,value)
    	end
    	return value
    end
    
    
    
    
    function object:Update()
    	if GetGlobalString("LE_Environment_mode") == "ENV_MODE_GAME" then
    		t = model:GetTarget(0)
    		if KeyHit(_G[object.key_forward])==1 then
    			t:SendMessage("move_forward")
    			AppLog("move_forward")
    		end
    		if KeyHit(_G[object.key_backward])==1 then t:SendMessage("move_backward") end
    		if KeyHit(_G[object.key_turn_left])==1 then t:SendMessage("turn_left") end
    		if KeyHit(_G[object.key_turn_right])==1 then t:SendMessage("turn_right") end
    	end
    end
    
    
    
    end
    

     

    BMX part:

     

    ...
    
    SetEntityCallback(Target, Byte Ptr MyMessageReceiveCallback, ENTITYCALLBACK_MESSAGERECEIVE)
    
    ...
    
    Function MyMessageReceiveCallback(entity:TEntity, message:String, extra:Object)
    If Entity Then
    	Print(message)
    End If
    End Function
    
    

     

    where Target is target entity linked to player entity in editor and readed to from func_gamecontrol entity.

  12. I have created entity function with send message method to target object. Now i need receive this message but from BMX.

     

    Note: When I tried send/receive message only with LUA - works very good. But send message from lua and receive to bmx doesn't work for me.

     

    Any ideas?

  13. I had same problem, ... because i forgot add functions for read and write values for user defined properties. Here is part of my code. I think that help you.

     

    
    function class:InitDialog(grid)
    
    self.super:InitDialog(grid)
    
    group = grid:AddGroup("GameProperties")
    group:AddProperty("classname", PROPERTY_STRING, "classname")
    
    
    group = grid:AddGroup("Key Binding")
    group:AddProperty("key_forward", PROPERTY_STRING, "KEY_UP","Key Forward")
    group:AddProperty("key_backward", PROPERTY_STRING, "","Key Backward")
    group:AddProperty("key_turn_left", PROPERTY_STRING, "","Key Turn left")
    group:AddProperty("key_turn_right", PROPERTY_STRING, "","Key Turn right")
    
    
    end
    
    function class:CreateObject(model)
    
    local object=self.super:CreateObject(model)
    
    object.classname = "func_gamecontrol"
    
    -- default key binds
    object.key_forward = "KEY_UP"
    object.key_backward = "KEY_DOWN"
    object.key_turn_left = "KEY_LEFT"
    object.key_turn_right = "KEY_RIGHT"
    
    
    
    function object:SetKey(key,value)
    	if key=="classname" then
    		object.classname = value
    	elseif key=="key_forward" then object.key_forward = value
    	elseif key=="key_backward" then object.key_backward = value
    	elseif key=="key_turn_left" then object.key_turn_left = value
    	elseif key=="key_turn_right" then object.key_turn_right = value
    	else
    		return self.super:SetKey(key,value)
    	end
    	return 1
    end
    
    
    
    function object:GetKey(key,value)
    	if key=="classname" then
    		return object.classname
    	elseif key=="key_forward" then return object.key_forward
    	elseif key=="key_backward" then  return object.key_backward
    	elseif key=="key_turn_left" then  return object.key_turn_left
    	elseif key=="key_turn_right" then  return object.key_turn_right
    
    	else
    		return self.super:GetKey(key,value)
    	end
    	return value
    end
    
           ...
    
    

×
×
  • Create New...