Adrstalik
New Member
- Joined
- Jul 21, 2009
- Messages
- 8
- Reaction score
- 0
Hey.
At the begining I'd like to thank you for attention.
[The main part]
I do not play Tibia since a long while. I was reading new documentation of Xenobot, and I have found something interesting. Well, I have found "New IPC Classes". Darkstar shows how it's working on, but I do not get it at all. Look at these pieces of code :
This is the responder socket, it must only be run on one client.
This is the subscriber socket. It can be run on any number of clients, and it will receive the messages broadcasted by the publisher.
I was wondering how to use it to communicate between MC1 and MC2.
For example. If MC1 is out of supplies, it send the signal to MC2 - "I am out of supplies, we're going back to town." Then MC2 react to this information and change label to "BackTown" or sth.
I have found this, is there any option to connect the ipc with this? Look:
Hope you understand what I mean.
// Adrstalik
At the begining I'd like to thank you for attention.
[The main part]
I do not play Tibia since a long while. I was reading new documentation of Xenobot, and I have found something interesting. Well, I have found "New IPC Classes". Darkstar shows how it's working on, but I do not get it at all. Look at these pieces of code :
This is the responder socket, it must only be run on one client.
Code:
local publisher = IpcPublisherSocket.New("test-ipc-pub-socket", 30123)
local count = 0
while (true) do
publisher:PublishMessage("Topic 1", "this is message #" .. count .. " on topic 1")
count = count + 1
wait(5000)
end
Code:
local subscriber = IpcSubscriberSocket.New("test-ipc-sub-socket", 30123)
subscriber:AddTopic("Topic 1")
while (true) do
local hasMessage, topic, data = subscriber:Recv()
while (hasMessage) do
print("[%s]: %s", topic, data)
hasMessage, topic, data = subscriber:Recv()
end
wait(200)
end
I was wondering how to use it to communicate between MC1 and MC2.
For example. If MC1 is out of supplies, it send the signal to MC2 - "I am out of supplies, we're going back to town." Then MC2 react to this information and change label to "BackTown" or sth.
I have found this, is there any option to connect the ipc with this? Look:
Code:
bluescript.lua
lua code:
------------------------------------------------
-- This is "Blue Script", it uses static classes
------------------------------------------------
wait(10000)
-- Check for any message for blue script.
Signal.OnReceive('blue-script', function(signal, data)
-- print red script's message
print('Red: ' .. data)
-- Send a message to red script, depending on the message received
if(data == 'Hello')then
Signal.Send('red-script', 'Hi red script!!!')
elseif(data == 'Bye')then
Signal.Send('red-script', 'See ya later.')
-- We said our farewells, lets kill this listener
signal:Close()
end
end)
redscript.lua
lua code:
--------------------------------------------------------
-- This is "Red Script", it uses object-oriented classes
--------------------------------------------------------
wait(10000)
local blue = Signal.New('blue-script')
local red = Signal.New('red-script')
-- Start the conversation, send a message to blue script
blue:Send('Hello')
-- Check for any message for red script.
red:OnReceive(function(signal, data)
-- print blue script's message
print('Blue: ' .. data)
-- Send a message to blue script, then kill the signal.
blue:Send('Bye.')
signal:Close()
end)
Hope you understand what I mean.
// Adrstalik