GML Im trying to make a server but the switch statement does not catch any of the 4 possible values.

I

imanster

Guest
var type = ds_map_read(async_load, "type");

switch(type)
{

case network_type_connect:
show_debug_message("Connected");
break;

case network_type_disconnect:
show_debug_message("Disconnected");
break;

case network_type_non_blocking_connect:
if(async_load[? "succeeded"]) {
state = "connection successful";
}
else {
state = "connection failed";
}
show_debug_message(state);
break;

case network_type_data:
show_debug_message("Received data message:" + msg);
break;

default:
show_debug_message("uncaught network event: " + string(type));
break;
}
 

FrostyCat

Redemption Seeker
Is this in the Networking event? Are there any conditions outside of what you showed that may prevent it from running?
 
I

imanster

Guest
No. I can see a message "uncaught network event: 0" continuously, for any message that the server sends.
 

Yal

🐧 *penguin noises*
GMC Elder
That probably is because you don't have any code catching them (i.e., the Networking event). Just a hunch.
 

Yal

🐧 *penguin noises*
GMC Elder
The accessory syntax is shorter, which in turn makes code feel nicer to write and makes it easier to read. Might as well use it whenever possible instead of remembering which function it corresponds to...
 
  • Like
Reactions: Roa

Greenwitch

Member
The accessory syntax is shorter, which in turn makes code feel nicer to write and makes it easier to read. Might as well use it whenever possible instead of remembering which function it corresponds to...
Unfortunately the manual that explains the async events are all using ds_map_find_value, not the accessor. So it's still important to know what is what.
 
However, the manual page for ds_map_find_value refers to the accessor as well:
Example:
amount = ds_map_find_value(inventory, "food");

Or, using the map accessor "?":

amount = inventory[? "food"];

The above code will get the value of the key "food" and store it in the variable "amount".
 

Yal

🐧 *penguin noises*
GMC Elder
I coincidentally wrote some code yesterday that used the [? ] accessor on async_load and it worked just fine. There's usually more than one way to do things in programming, and rarely only one "right" way.
 
Top