GML [Solved] Can a case in a switch statement have a negative value?

X

XirmiX

Guest
Quick question, since I don't want to write a whole bunch of code having these values set up and then it turning out to not work. Essentially, I want to know whether something like this:

Code:
switch(some_thing)
{
    case 1:
  
    break;
    case -1:
   
    break;
}
Is that okay, or a no-go and it's not going to work or respond in any way, or is going to create glitches? I do need the cases to be separate cases still, of course, so no relation between a case that is 1 and a case that is -1. Reason I wanna have it like this is, well, in terms of networking:

Client sends data of case 1 to the server about itself. The server reads it and sends it to other clients through case 1 as well. Now, the client will need to receive this information... it can't use case 1, because that's already occupied with sending info, and you can't have the sending and receiving of info mix-and-match for the client, because it sends information about itself, whilst receives information about all the other clients, so it doesn't work out. Now, if it's case 2 that could work, but you must remember that the more content is being added, the messier this will get. If I don't want it to get messy, this could really help me out. Otherwise, I'll need to keep track of things, a mess might be created, and I will have a limit to how much content I can add to my game without creating a mess. Sure, starting with case 100 for the client receiving data could work, but still be messy. Though, if that's what I'll have to resort to, then that's what I'll resort to, I guess.

EDIT: as an additional question, can I use case 0?
 
Yes , you can use 0 and -1 in a switch statement for the case. I don't know that you can apply it to everything, but when using sign( x - other.x), for example, it can be either 0 / 1 / -1, and that works in a switch
 
X

XirmiX

Guest
Yes , you can use 0 and -1 in a switch statement for the case. I don't know that you can apply it to everything, but when using sign( x - other.x), for example, it can be either 0 / 1 / -1, and that works in a switch
Oh, thank yoyo games! That's convenient, thank you for the reply as well :)
 
Top