Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Error: attempt to index local 'self' (a nil value)" in string.split function
    primarykey
    data
    text
    <p>Quick facts, I got this function from <a href="http://lua-users.org/wiki/SplitJoin" rel="nofollow">http://lua-users.org/wiki/SplitJoin</a> at the very bottom, and am attempting to use it in the Corona SDK, though I doubt that's important.</p> <pre><code>function string:split(sSeparator, nMax, bRegexp) assert(sSeparator ~= '') assert(nMax == nil or nMax &gt;= 1) local aRecord = {} if self:len() &gt; 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 </code></pre> <p>The input: "1316982303 Searching server"</p> <pre><code>msglist = string.split(msg, ' ') </code></pre> <p>Gives me the error in the title. Any ideas? I'm fairly certain it's just the function is out of date.</p> <p>Edit: lots more code Here's some more from the main.lua file:</p> <pre><code>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 &gt; 0 do argname = "arg" .. argCount _G[argname] = arglist[0] table.remove(arglist, 0) argCount = argCount + 1 end </code></pre> <p>Server.py: This is the multiplayer server that sends the necessary info to clients.</p> <pre><code>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) &gt; 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() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload