Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
Is there another way to do this code without using Invoke:
public void Onmessage(object s, PlayerIOClient.Message m)
{
Invoke(new EventHandler(delegate
{
switch (m.Type)
{
#region Init
case "init":
{
con.Send("init2");
con.Send("say", "Hi!");
}
break;
#endregion
}
}));
}
Offline
why not just
public void Onmessage(object s, PlayerIOClient.Message m)
{
switch (m.Type)
{
case "init":
{
cl.con.Send("init2");
cl.con.Send("say", "Hi!");
}
break;
}
}
Offline
This did not work, it won't even recognize any message coming in
Offline
Is he trying to use client to send messages? Why is there cl.con.send?
Offline
Did you do this?
con.OnMessage += new MessageReceivedEventHandler(messageHandler.handlemsg);
yes i have
and
i've removed the cl, i had the event loader in a class before and had the class be a form but that didn't work, so i removed it sorry about that
Offline
yea, that's weird.
First get a client
var Client = PlayerIO.QuickConnect.SimpleConnect({gameid}, {email}, {pass}, null);
then get a connection
var con = Client.Multiplayer.CreateJoinRoom({worldid},"Everybodyedits"+Client.BigDB.Load("config","config")["owner"], true, null, null)
Now set up message handler
you can do this in 2 ways.
1.
con.Send("init");
con.OnMessage += OnMessage;
public void OnMessage(object sender, Message m)
{
if(m.Type == "init")
{
con.Send("init2");
}
}
2.
con.Send("init");
con.OnMessage += (o,m) =>
{
if(m.Type == "init")
{
con.Send("init2");
}
}
To send messages use connection:
con.Send("init")
Offline
I'm running into a really confusing bug. I'm not actually sure if it's connecting or not. It returns the connected value as true, but he doesn't show up in the world until I refresh or open a new tab, my friend's list says he's still offline, any database i check says i'm offline. I'm not really sure what's happening.
Offline
Bots are offline becasue they don't connect to the lobby.
make sure you:
1) sent "init"
2) when recieved "init" you sent "init2"
or, even better, show your code. (make sure to hide email and password if it's hardcoded)
Offline
i ended up finding the mistake, i was sending "inut" instead of "init" lol i guess it's 5:15 AM and I still haven't gone to bed so that explains that, thank you so much for helping me with such a silly mistake.
Offline
Just to let you know, you may need to use invoke if you are using forms or timers or anything, as if you dont, you can run into threading problems. Using Invoke right at the start though is actually a clever way to fix this that I hadnt thought of before... :O
If you do want to use it though, I would advise doing this instead, as it looks better, and is probably a bit faster as you dont create events every time a message is recieved:
public void Onmessage(object s, PlayerIOClient.Message m)
{
switch (m.Type)
{
case "init":
{
con.Send("init2");
con.Send("say", "Hi!");
}
break;
}
}
// Somewhere else
con.OnMessage += (s, m) => BeginInvoke((Action<object, Message>)OnMessage, s, m);
This way you are effectively changing a multithreaded program (one main thread and one thread for PlayerIO) into a single threaded program, so you should no longer get the usual problems associated with threading
Offline
This way you are effectively changing a multithreaded program (one main thread and one thread for PlayerIO) into a single threaded program, so you should no longer get the usual problems associated with threading
true, but then you get the usual problem with threading: putting your UI and work tasks on the same thread. While the way you suggest is easier and more manageable imo, I don't think it's the optimized course of action
Offline
destroyer123 wrote:This way you are effectively changing a multithreaded program (one main thread and one thread for PlayerIO) into a single threaded program, so you should no longer get the usual problems associated with threading
true, but then you get the usual problem with threading: putting your UI and work tasks on the same thread. While the way you suggest is easier and more manageable imo, I don't think it's the optimized course of action
Well yes, but for most bots youre limited mostly by internet speed, not by time taken to actually do things. The only bot Ive made that was limited by processing time was Mars Mine, and it only happened when generating the world (a few seconds every hour or so), so didnt really matter
Edit: Just remembered there were also a few JavaScript things too, but... well... its JavaScript, so you cant really compare it to the speed of C# etc.
Offline
[ Started around 1732213749.9314 - Generated in 0.079 seconds, 14 queries executed - Memory usage: 1.54 MiB (Peak: 1.71 MiB) ]