Jump to content

I need help with Reseive message


AndyGFX
 Share

Recommended Posts

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?

[HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64

[sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx

 

76561197970156808.pngAndyGFX.png

Link to comment
Share on other sites

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.

[HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64

[sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx

 

76561197970156808.pngAndyGFX.png

Link to comment
Share on other sites

My first assumption is that you aren't setting the right entity to receive the message. Check into model entity vs mesh entities. Your target might be the mesh and in your BMax code you might be assigning the callback to the model. Play around with that once.

Link to comment
Share on other sites

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.

[HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64

[sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx

 

76561197970156808.pngAndyGFX.png

Link to comment
Share on other sites

not looked at the problem completely... but where in this lua script do you have the keycodes set (require("Scripts/constants/keycodes"))? are they set elsewhere? or did you just forget for your example?

 

Edit- I just tried your lua code loaded by a bmax program along with adding to the top of the lua script

require("Scripts/constants/keycodes")

, and it works just fine. As long as you are sure that the target you are accessing in bmax is the same target you are getting in lua, it responds correctly.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

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.

[HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64

[sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx

 

76561197970156808.pngAndyGFX.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...