Announcement

Collapse
No announcement yet.

GUI timer question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    GUI timer question

    Well, been playing around with this all day from about 80 different angles and I'm still stuck, so I figured I'd see if any of you know a better way. I'll break it up into two sections so you can skip to the stuff you want


    // Background info on the problem

    I've set up a menu that I want to take information passed in a message from a (modified) TCPlink class and use it to fill in some of its fields.

    I'm starting off simple by requesting a string from my server using an instance of myTCPlink within my GUIpage, then trying to take the string it returns and set it to be the caption in a GUIlabel.

    The problem is that there is, of course, some latency between the time my guiPage opens the socket and requests the string and the time it actually recieves the string. However there doesn't seem to be any way to wait for any length of time since GUIpage is a subclass of object and not actor i cant use sleep, tick, or anything else like them to poll for the string.

    Just to make sure it was actually being sent i created an "update" button that manually checks the myTCPlink instance for the string and updates the label, and that works, but I want it done automatically.



    // actual question
    myTCPlink recieves a notification when the string is recieved from the event TextRecieved but I cant figure out how to pass it on at that time to a function in my GUIpage so it can update the labels. How can I do so? As always any help is greatly appreciated.

    #2
    Objects can tick if I recall, you have to enable it though...

    Comment


      #3
      How about defining a delegate in your TCPLink class and assign a function in your GUI class to it?

      For example:
      Code:
      class YourTCPLink extends TCPLink;
      
      delegate OnTextReceived(string Text);
      
      event TextRecieved(string Text)
      {
        OnTextReceived(Text);
      }
      Code:
      class YourGUIPage extends GUIPage; // or whatever
      
      // (...)
      
      theLink = Spawn(class'YourTCPLink');
      theLink.OnTextReceived = AddTextToGUI; // Important: No parantheses here!
      
      // (...)
      
      function AddTextToGUI(string Text)
      {
        // add the text
      }
      Just remember to set the delegate to None after you're done, otherwise you might experience some garbage-collection issues that might cause crashes or trigger cheat protections.

      Comment


        #4
        Hmm Apparantly there is a bAlwaysTick that I can use in myTCPlink but I havn't found a way to get objects to tick. If you find it please let me know it'd save me a lot of future headaches.

        And thanks for pointing out delegates, I hadn't heard about them before but it should work out nicely here.

        Thanks =)

        Comment


          #5
          last time i checked u couldnt do tick() in GUI, I did:
          Code:
          Class Yea-You-Get-It ...;
          
          function InitComponent(GUIController MyController, GUIComponent MyOwner)
          {
              ...
              SetTimer(0.001,True);
          }
          
          event Timer()
          {
              ...
          }

          Comment


            #6
            Wormbo has the right idea.

            Since TCPLink has a native event for when IT recieves text, you can then create a delegate function in your gui page and have your TCPlink call that delegate function when it recieves the text. Tick or timer arent needed if you do it this way.

            Comment


              #7
              wth is a delegate?

              Comment


                #8
                Did you actually read my post above?
                If that didn't help you, try searching the Unreal Wiki for "delegate".



                "What's the UnreakWiki?" - Open your eyes.

                Comment


                  #9
                  i ddi but i couldnt understand it lol

                  Comment


                    #10
                    Not only that, but I must add that the wiki is a little unclear on delegates. Unusual for wiki, I get more out of this thread than I do from wiki about delegates.

                    The only thing I dont get about the delegate example, maybe someone can clarify.

                    You have the delegate function OnTextReceived(string Text). Got that. Then you have that being called by the event TextReceived(string Text).

                    Well, then in the GUI page or whatever, you have the theLink.OnTextReceived set to your function you define there. Got it.

                    Does that mean when the event TextReceived is called, it will then call the function OnTextReceived, which is now pointing to the function AddTexttoGUI?

                    Comment


                      #11
                      Yeah, that's pretty much how they work, heh. Sort of like variables and functions at the same time. It's neat.

                      Comment


                        #12
                        Originally posted by cknight52
                        Not only that, but I must add that the wiki is a little unclear on delegates. Unusual for wiki, I get more out of this thread than I do from wiki about delegates.
                        Then by all means update the page! Otherwise it will never become more understandable for others.

                        Comment

                        Working...
                        X