Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6654355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:22:51+00:00 2026-05-26T01:22:51+00:00

Quick facts, I got this function from http://lua-users.org/wiki/SplitJoin at the very bottom, and am

  • 0

Quick facts, I got this function from http://lua-users.org/wiki/SplitJoin at the very bottom, and am attempting to use it in the Corona SDK, though I doubt that’s important.

function string:split(sSeparator, nMax, bRegexp)
    assert(sSeparator ~= '')
    assert(nMax == nil or nMax >= 1)

    local aRecord = {}

    if self:len() > 0 then
        local bPlain = not bRegexp
        nMax = nMax or -1

        local nField=1 nStart=1
        local nFirst,nLast = self:find(sSeparator, nStart, bPlain)
        while nFirst and nMax ~= 0 do
            aRecord[nField] = self:sub(nStart, nFirst-1)
            nField = nField+1
            nStart = nLast+1
            nFirst,nLast = self:find(sSeparator, nStart, bPlain)
            nMax = nMax-1
        end
        aRecord[nField] = self:sub(nStart)
    end

    return aRecord
end

The input: “1316982303 Searching server”

msglist = string.split(msg, ' ')

Gives me the error in the title. Any ideas? I’m fairly certain it’s just the function is out of date.

Edit: lots more code
Here’s some more from the main.lua file:

multiplayer = pubnub.new({
    publish_key   = "demo",             
    subscribe_key = "demo",             
    secret_key    = nil,                
    ssl           = nil,                -- ENABLE SSL?
    origin        = "pubsub.pubnub.com" -- PUBNUB CLOUD ORIGIN
})


multiplayer:subscribe({
    channel  = "MBPocketChange",
    callback = function(msg)
        -- MESSAGE RECEIVED!!!
        print (msg)
        msglist = string.split(msg, ' ')
        local recipient = msglist[0]  --Get the value
        table.remove(msglist, 0)     --Remove the value from the table.
        local cmdarg = msglist[0]
        table.remove(msglist, 0)
        arglist = string.split(cmdarg, ',')
        local command = arglist[0]
        table.remove(arglist, 0)
        argCount = 1
        while #arglist > 0 do
            argname = "arg" .. argCount
            _G[argname] = arglist[0]
            table.remove(arglist, 0)
            argCount = argCount + 1
        end

Server.py:
This is the multiplayer server that sends the necessary info to clients.

import sys
import tornado
import os
from Pubnub import Pubnub

## Initiat Class
pubnub = Pubnub( 'demo', 'demo', None, False )

## Subscribe Example
def receive(message) :
    test = str(message)
    msglist = test.split()
    recipient = msglist.pop(0)
    msg = msglist.pop(0)
    id = msglist.pop(0)
    if id != "server":
        print id
        print msg
        commandHandler(msg,id)
        return True

def commandHandler(cmd,id):
    global needOp
    needOp = False
    global matchListing
    if server is True:
        cmdArgList = cmd.split(',')
        cmd = cmdArgList.pop(0)
        while len(cmdArgList) > 0:
            argument = 1
            locals()["arg" + str(argument)] = cmdArgList.pop(0)
            argument += 1
        if cmd == "Seeking":
            if needOp != False and needOp != id:
                needOp = str(needOp)
                id = str(id)
                pubnub.publish({
                    'channel' : 'MBPocketChange',
                    #Message order is, and should remain:
                    #----------Recipient, Command,Arguments, Sender
                    'message' : needOp + " FoundOp," + id + " server"
                })
                print ("Attempting to match " + id + " with " + needOp + ".")
                needOp = False
                matchListing[needOp] = id
            else:
                needOp = id
                pubnub.publish({
                    'channel' : 'MBPocketChange',
                    #Message order is, and should remain:
                    #----------Recipient, Command,Arguments, Sender
                    'message' : id + ' Searching server'
                })
                print "Finding a match for: " + id
        elif cmd == "Confirm":
            if matchListing[id] == arg1:
                pubnub.publish({
                    'channel' : 'MBPocketChange',
                    #Message order is, and should remain:
                    #----------Recipient, Command,Arguments, Sender
                    'message' : arg1 + ' FoundCOp,' + id + ' server'
                })
                matchListing[arg1] = id
            else:
                pass #Cheater.
        elif cmd == "SConfirm":
            if matchListing[id] == arg1 and matchListing[arg1] == id:
                os.system('python server.py MBPocketChange' + arg1)
                #Here, the argument tells both players what room to join.
                #The room is created from the first player's ID.
                pubnub.publish({
                    'channel' : 'MBPocketChange',
                    #Message order is, and should remain:
                    #----------Recipient, Command,Arguments, Sender
                    'message' : id + ' GameStart,' + arg1 + ' server'
                })
                pubnub.publish({
                    'channel' : 'MBPocketChange',
                    #Message order is, and should remain:
                    #----------Recipient, Command,Arguments, Sender
                    'message' : arg1 + ' GameStart,' + arg1 + ' server'
                })
            else:
                pass #hax
    else:
        pass


def connected():
    pass

try:
    channel = sys.argv[1]
    server = False
    print("Listening for messages on '%s' channel..." % channel)
    pubnub.subscribe({
        'channel'  : channel,
        'connect'  : connected,
        'callback' : receive
    })
except:
    channel = "MBPocketChange"
    server = True
    print("Listening for messages on '%s' channel..." % channel)
    pubnub.subscribe({
        'channel'  : channel,
        'connect'  : connected,
        'callback' : receive
    })

tornado.ioloop.IOLoop.instance().start()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:22:52+00:00Added an answer on May 26, 2026 at 1:22 am

    This error message happens if you run:

    string.split(nil, ' ')
    

    Double check your inputs to be sure you are really passing in a string.

    Edit: in particular, msglist[0] is not the first position in the array in Lua, Lua arrays start at 1.

    As an aside, this function was written when the intention that you’d use the colon syntactic sugar, e.g.

    msglist=msg:split(' ')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the well know select algorithm. see http://en.wikipedia.org/wiki/Selection_algorithm . I need it to
Does somebody know a quick and easy explode() like function that can ignore splitter
this is a really stupid question but I have a deadline and I'm very
Looking to do a very small, quick 'n dirty side project. I like the
I'm going to list several quick facts for better understanding of my goal. Am
This is quite a quick question. I currently use* do_this if (testvar ||= false)
I've got a strange situation where deleting and creating directories in quick succession on
I had found written in python, a very simple http server, it's do_get method
Quick disclaimer, this is a contrived example meant to simulate an issue I am
I had this question during an exam, and I couldn't find a quick answer.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.