Announcement

Collapse
No announcement yet.

Renaming Tables

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

  • Renaming Tables

    OK this as mostly been covered somewhere if so please link me lol

    I have a table I want to rename

    Client = {}

    Client['clientname'] = {
    id='',
    handle='',
    ip=''
    }

    I want to replace 'clientname' without losing the details in the table, I am using web's sockets demo and trying to convert his multi chat demo to support more like private messages that only get sent to one given user, I really don't understand how hes done it its really confusing me lol

    looks like he collects all the in coming messages and the pushs them back out to all the clients, this is good but trying to make it work 1to1 is killing my brain cells lol

    What I have done so is the you connect to the server and the server sends back a username request what in the future can be bind to your IP, the client and server send room:user:message:addedswtichs
    eg
    mainroom:all:hello world:none
    this will send the messange to everyone

    priavte will be mainroom:jamesrivate message:switch

    so I need the username to be part of the table I not really sure how to loop thought the table to find the right handle but that is also a option :P
    Plugins or Sources MokoX
    BunnyHop 2021 Here

  • #2
    ok this is an example
    PHP Code:
    Client = {"9","6","8"} -- original table

    client_name
    Client -- copy it to new name

    Client
    = {} -- delete the original 

    Comment


    • #3
      Indeed, when you want to rename a table, you can simply copy the reference.
      When you assign your table value to a new variable, it will only copy the reference
      to the table, not the actual data itself. You can then safely delete the original table
      by setting the value to nil. As long at least one variable is referring to the table, the
      garbage collector will not remove it.

      Code:
      Client = {}
      
      Client['clientname1'] = {
      	id	= 'id1';
      	handle	= 'handle1';
      	ip	= '1.1.1.1';
      }
      
      Client['clientname2'] = {
      	id	= 'id2';
      	handle	= 'handle2';
      	ip	= '2.2.2.2';
      }
      
      Client['clientname3'] = {
      	id	= 'id3';
      	handle	= 'handle3';
      	ip	= '3.3.3.3';
      }
      
      -- Now let's rename clientname2
      Client['newname']     = Client['clientname2'];
      Client['clientname2'] = nil;
      
      
      for name, clientInfo in pairs(Client)do
      	Dialog.Message(name, clientInfo.id);
      end
      Bas Groothedde
      Imagine Programming :: Blog

      AMS8 Plugins
      IMXLH Compiler

      Comment


      • #4
        thanks guys seeing it like that help a lot
        Plugins or Sources MokoX
        BunnyHop 2021 Here

        Comment


        • #5
          Wazaaaaa! The chat client I made was just an example of how to use coroutines with lua sockets to build a server, but I´m not using an standard communication protocol. You can build your own protocol to execute some functions, etc. If you need any extra help let me know.

          Comment


          • #6
            Originally posted by webultra View Post
            Wazaaaaa! The chat client I made was just an example of how to use coroutines with lua sockets to build a server, but I´m not using an standard communication protocol. You can build your own protocol to execute some functions, etc. If you need any extra help let me know.
            Help is a big think I do need web, if you have gmail I could explain my idea in full detail, yes I was trying to start using your example to make a new idea, but every time I tried adding a way to send a message to one client only I failed

            Nice to see you about web
            Plugins or Sources MokoX
            BunnyHop 2021 Here

            Comment


            • #7
              Check your PM inbox

              Comment

              Working...
              X