angelwire
Member
EDIT: I'll leave this up as an sad reminder of how dumb I look.
I had accidentally swapped "!= undefined" and "== undefined" and so I thought it was returning "undefined" when it was actually returning the player and visa-versa.
Everything in this post is wrong
Using 2.3
I'm making a multiplayer game using the upd protocol and I want to map objects to the player's IP address. I'm getting the IP address from the initial network async event and creating an object to put in the map with the IP as the key.
When I tried to use it IP address as the key for the player object it kept coming back as undefined. I did a lot of double checking debugging and debugging to make sure the IP address and player were added to the ds_map. Eventually I found out that I needed to append a " to both sides of the IP address in order to retrieve the player from the map.
The only thing I can think of is that there is some internal logic in ds_maps that are somehow trying to use the IP address as a number key instead of string key. Does anyone have any ideas about whether this is the case or not? If so is there anything I can do about it to not use "\"" every time I access the ds_map?
Here are the snippets of code I'm using:
Thank you!
I had accidentally swapped "!= undefined" and "== undefined" and so I thought it was returning "undefined" when it was actually returning the player and visa-versa.
Everything in this post is wrong
Using 2.3
I'm making a multiplayer game using the upd protocol and I want to map objects to the player's IP address. I'm getting the IP address from the initial network async event and creating an object to put in the map with the IP as the key.
When I tried to use it IP address as the key for the player object it kept coming back as undefined. I did a lot of double checking debugging and debugging to make sure the IP address and player were added to the ds_map. Eventually I found out that I needed to append a " to both sides of the IP address in order to retrieve the player from the map.
The only thing I can think of is that there is some internal logic in ds_maps that are somehow trying to use the IP address as a number key instead of string key. Does anyone have any ideas about whether this is the case or not? If so is there anything I can do about it to not use "\"" every time I access the ds_map?
Here are the snippets of code I'm using:
GML:
//Async networking when player connects
var _ip = async_load[? "ip"];
var _player = instance_create_layer(0,0,"Instances", player_obj);
ds_map_add(player_map, _ip, _player);
//Async networking when player moves
var _ip = async_load[? "ip"];
_player_instance = player_map[? string(_ip)]; //undefined
_player_instance = ds_map_find_value(player_map, string(_ip)); //undefined
_player_instance = ds_map_find_value(player_map, "\"" + string(_ip) + "\""); //This works
Last edited: