How do I Construct 2 like a Pro? Values Question

Get help using Construct 2

Post » Mon Apr 03, 2017 11:14 pm

Let's keep it simple,


I have two values,

Value X and Value Y


Value X and Y can both be any number possible so we don't know how long the value will be.

X= ? Y = ?

Now we want to send Value X and Value Y as a message to the host in the multiplayer plugin.

So I ask you, How do we figure out where Value X ends and where Value Y begins?
B
23
S
8
Posts: 115
Reputation: 2,640

Post » Mon Apr 03, 2017 11:25 pm

Separate them with a token ("," generally works well) when composing the message and use tokenat() on the host side to parse out the pieces.

https://www.scirra.com/manual/126/system-expressions
Mistakes were made.
B
52
S
26
G
111
Posts: 1,628
Reputation: 62,677

Post » Tue Apr 04, 2017 9:57 pm

Could you possibly show me how you would separate them two values?

I can send the message but I keep having a problem with converting strings to values.

So it's kinda like it gets sent but then you end up with multiplayer message so the tokenat thing isn't really working out how I would of liked it to.
B
23
S
8
Posts: 115
Reputation: 2,640

Post » Tue Apr 04, 2017 10:18 pm

So peer sends message "2.13123,32.1234"

Host receives the message, saves it to a variable (or array or dictionary or instance variable ect.)
On peer message - set SavedMessage to Multipayer.Message

To get the first value as a float, use float(tokenat(SavedMessage,0,",")) - returns 2.13123 as a value.
To get the second value, use float(tokenat(SavedMessage,1,",")) - returns 32.1234 as a value

You can use tokenat directly on Multiplayer.Message itself instead of saving it to an intermediate storage variable first if you don't need the value to persist.
Mistakes were made.
B
52
S
26
G
111
Posts: 1,628
Reputation: 62,677

Post » Wed Apr 05, 2017 1:48 am

First off thank you so much oosyrag for all your help.

This is what I got so far,

FROM PEER
On left mouse button down.
Send message to host str(value1|value2)

ON HOST SIDE
on peer message > set global value to multiplayer message.
set text to global value

Error prints out " 1 "
But should so 1 = value 1 5 = value 2

What's wrong with this?
B
23
S
8
Posts: 115
Reputation: 2,640


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, valefor and 6 guests