• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Having to append " to an IP address to use in a ds_map [Solved - I was totally wrong]

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:
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
Thank you!
 
Last edited:

chamaeleon

Member
Well, _ip is a string to begin with (that is, the async_load[? "ip"] content), so no wrapping of it using string() should be needed at all. The quotes should not be necessary either. If I were you I'd put a breakpoint or otherwise debug (show_debug_message(), etc) the content of the player_map to see what the keys are before and after adding elements to it.
 

angelwire

Member
Long day of coding and I'm an idiot. I had a "!= undefined" when it should have been "== undefined". So I thought it was returning undefined when it was actually working. I just needed to debug in the right place. Nothing is wrong with the ds_maps. My apologies for the confusion.
 
Top