Off Topic > Off Topic
Programming Megathread
<< < (174/241) > >>
Timestamp:
do any of you guys use programmr.com as a learning site also?
McJob:
So, I'm working with code that a previous intern did on a big platform. Most of our networking stuff is handled by an external plugin called GameSparks (IIRC), which you can go buy and use as well. One of the values provided by GS is a constant called GS_TIMEOUT which is the default connection timeout. Every other script that needs to rely on connecting to something uses the GS_TIMEOUT value so it's all consistent.

I was trying to document some cryptic functionality for the menu builder (don't even get me started on that) and in doing so, I noticed that our main menu times out after 6 seconds, instead of the GS_TIMEOUT value of 20. After traveling through about a million scripts to find the one related to the menu connections, I stumbled across this code snippet:


--- Code: ---    void Update {

      // Leaving a check here in case GameSparks connection times out.

      float temp = Time.time - startTime;  
      int constraint = 6;
      if ((int) temp == constraint){        
        string retryButton = "Retry";
        PopupSystem.Instance.PopupMessageBox(UT.Lang("GameSparks connection timed out."), retryButton, Restart);
--- End code ---

If any of you programmers would like to chime in on why you think this is wrong, I'd love a good laugh right about now.
Metario:
converting a float to a int?
edit: oh your just comparing the time and seeing if it's above 6 seconds then popping the retry button
should be using GS_TIMEOUT to define it instead
ZSNO:
Looks like it's checking if the time elapsed is about 6 seconds. Which is bad, should change it to greater or equal to 6 seconds.
McJob:
Casting a float to an int is pretty bad, because in C# you have access to the .Floor() and .Ceil() methods, and using equal-to as opposed to checking if it's greater-than-or-equal-to is very stupid, but even then, not using floats for time tracking is pretty bad, especially when Unity's time functions are all floats/doubles. Using a magic number/local variable instead of making a public class property or just using the GS_TIMEOUT const is pretty ignorant.

The one thing I thought of this morning is that it'd actually be better suited to a coroutine/callback method, which are littered ALL over the rest of the code and so I'm not quite sure why chose to handle this in Update(), which is called once per frame, every frame.
Navigation
Message Index
Next page
Previous page

Go to full version