Hi! I’ve been trying to get this to work, and it’s relatively simple. I want to know which object a specific object is colliding. In my game, I’m working with Peer-2-Peer. If my object is in collision with a group “Ps”, with many objects, I want to save a string variable with the name of the object from the group colliding with “Star” and then send an event to all clients, using that variable as the extra data.
Edit: I’ve seen another topic like this one, but it doesn’t say how to use this “Ps.ObjectName()” method and I want to see how.
Your use of ObejctName() appears ok. Are you passing the global variabel SP, or the scene variable SP? The icon looks incorrect in the Trigger event on all connected clients...
Also, I don’t think that last line where you are using GlobalVariable(SP) is correct - it’s using the global variable of this client, not the value the other client sent (obtained using P2P::GetEventData("SP"))
Edit: The variable IsClient is from the P2P, in this case is false, so I don’t have to open another window to test the game. About the conditions in the first event, the variables contain the position of each object. The “a” variable and Dragged, are both variables to check the same, if the object has moved.
Note: If the event system worked, it would delete “Star”, that’s why it’s there, to debug.
Just relized a problem, I’m using the GetEvenetData wrong, by putting the variable (SP) instead of the event (SPS). Although I changed that and nothing happened. Also I changed the global variables to scene variables and nothing either.
Picture of changed code:
Just to be clear, and it’s my fault, in GetEventData(“x”), where the x is, do you put the name of the event or the name of the variable?
Edit: I ended up changing the variable names to “SPDS”, the variables and the events, so it’s just like before. Also, “SPDS” is a non-existent variable, which was one of my fears (that it didn’t work because it was being used and changing other events).
Picture of last modified code, debugged everything I thought could be trouble or faulty:
Ok. I changed it and it’s still not working. The code is the same as the last screenshot I sent, but the variable name is “SP”, so the events are still “SPDS”. I think the problem is either sending (or receiving) the event, because if it was working, Star would be deleted.
Sorry, I didn’t look at your events before, and unfortunately they’re probably going to create a star at 0,0 at best. This is because you are passing a string (SP which is set to Ps.ObjectName()), yet you are treating it as a number (ToNumber(P2P::GetEventData(“SP”)).
And to confirm, you are using 2 instances of the game that are connected via P2P?
The Star is not in 0,0. It is in a custom position. The SP variable is a string, but GetEventData requires a number, so I don’t really know how to “translate” (I was hoping you could give me a solution). And yes, the game is played on two windows with P2P, one is a client, thus the variable IsClient.
For sure, you won’t be left high and dry. To confirm my understanding, are you aiming to pass the co-ordinates of the star to the client machine? And it’s a one way thing - the ‘master’ client only sends the updates to the other client?
Yes, for now. My goal is that if a client moves an object, Star for example, that position is sent to the Master and updated in the master scene, and vice versa. The game is chess, I think thats a better way to picture it. One moves a piece and sends an update, and then the same with the other player. So I’d say both, a “two way” thing.
The second and third events will will only fire if they’re on the machine with IsClient = false. So the non-client sends the message to a client that’s not listening, and the non-client listens for messages that are never sent by the client, I don’t think that what you’re after.
Do you need to check IsClient when sending a message/triggering an event?