Each object in blender has a “key” that is it’s unique object address
like
own = cont.owner
so if I convert this to a string, for network message,
own.sendMessage_“Subject,str(own)”
I can’t convert it back…
I need
target = key(message.bodies[0])
to convert a string into a game object address, or UUID or whatever you want to call it.
Edit - Solution Send ID not object key,
agoose77
(agoose77)
March 10, 2014, 2:51pm
#2
Each object in blender has a “key” that is it’s unique object address
like
own = cont.owner
so if I convert this to a string, for network message,
own.sendMessage_“Subject,str(own)”
I can’t convert it back…
I need
target = key(message.bodies[0])
to convert a string into a game object address, or UUID or whatever you want to call it.
Try this
http://www.tutorialsforblender3d.com/GameModule/ClassCListValue_3.html
Ok still a no go for sending as a string and converting back…
found a work around using scene.objects
I am adding the items with a “Factory”
so I can store the added item keys in a list to be recalled instead of scene.objects
if I get that heavy into this.
Attachments
Solution.blend (503 KB)
agoose77
(agoose77)
March 10, 2014, 3:25pm
#5
I cannot see the problem.
Attachments
slution.blend (541 KB)
Never mind,
I see you have send and receive in the script as modules,
Edit:still points at the same object as the message problem…
Here is the solution you proposed hacked in,
Space = spawn unit
B= spawn factory
try space,b,space,b (there is a timer)
mine works, the other solution does not,
in solutionnope, I send a message in text.003 and receive via text.004 but both track factory 1
in solution(1) I just sort through and find the workers,
Attachments
Solution (1).blend (503 KB)Solutionnope.blend (508 KB)
agoose77
(agoose77)
March 10, 2014, 4:08pm
#8
Your example files are far too complex, and without documentation. From what you’ve told me, it seems to work. Have you ensured the subjects for the messages are correct?
sender-
if sens.positive:
(tab)own.sendMessage(“Factory”,str(id(own)))
reciever
if message.positive:
get_obj = own.scene.objects.from_id
obj = get_obj(int(message.bodies[0]))
own[‘target’]=obj
and I use the target to move the navtarget,
in this example it both points to factory 1
in mine worker 1 goes to factory 1, and worker 2 goes to factory 2
Ok documentation,
“Ai factory adds Ai” Ai spawns navtarget - space key
if Ai[‘target’]!=Empty -> move navtarget to target, activate steering
Factory Factory B key
adds “factory”
Factory sends message subject “Factory” body - str(id(own))
Ai receives and does,
get_obj = own.scene.objects.from_id
obj = get_obj(int(message.bodies[0]))
own[‘target’]=obj
in solution(1)
I just cycle through scene .objects and set target and working=true
Edit: -> NM I found the error of my ways, they were just all getting the next message
reciever
import bge
from bge import logic
cont = bge.logic.getCurrentController()
own = cont.owner
scene=logic.getCurrentScene()
message=cont.sensors['Message']
if message.positive:
import bge
from bge import logic
cont = bge.logic.getCurrentController()
own = cont.owner
scene=logic.getCurrentScene()
message=cont.sensors['Message']
prop=cont.sensors['prop']
if message.positive and prop.positive:
get_obj = own.scene.objects.from_id
obj = get_obj(int(message.bodies[0]))
own['target']=obj
own['working']=True
prop is a property
Working=False
Thanks Goose, now I think I can actually use .sendMessage for many things,
Attachments
Solutionnope1.blend (510 KB)
We need a “solved by” so that kudos can go to solvers.