Jump to content

Class chat error


Recommended Posts

bad argument #1 for 'ipairs' (table expected, got nill)

  
  
  
function classchat(player, command, ...) 
         
        local message = table.concat(arg, " ") 
         
        local classmembers = getElementData(player,"class") 
        for i,v in ipairs(classmembers) do 
                outputChatBox("*CLASS*" .. getPlayerName(player) .. ": " .. message ,255, 100, 0, true) 
            end 
        end 
addCommandHandler("class", classchat) 
  
  

Edited by Guest
Link to comment
bad argument #1 for 'ipairs' (table expected, got nill)
  
  
  
function classchat(player, command, ...) 
         
        local message = table.concat(arg, " ") 
         
        local classmembers = getElementData(player,"class") 
        for i,v in ipairs(classmembers) do 
                outputChatBox("*CLASS*" .. getPlayerName(player) .. ": " .. message ,255, 100, 0, true) 
            end 
        end 
addCommandHandler("class", classchat) 
  
  

Link to comment
function classchat(player, command, ...) 
        local message = table.concat({...}, " ") 
        for i,v in ipairs(getElementsByType("player")) do 
                if ( getElementData ( v, "class" ) ) then 
                      outputChatBox("*CLASS*" .. getPlayerName(player) .. ": " .. message , v, 255, 100, 0, true) 
                end 
        end 
end 
addCommandHandler("class", classchat) 

Try This ^

Link to comment
# hmmm, what you need ?

It's obvius ... A teacher has stutends and he want to only talk to them.

@scaryface87: you used this instruction to get the class:

local classmembers = getElementData(player,"class")

but how do you set it ? Can you show us how you create the table and how do you set it as an element data ? Thanks

Im a little bit confused?

It sets the element data on playerspawn (i already used getElementData for other things so dont rlly htink its a problem there)

h"how you create the table" what u meaN?

Link to comment
  • Moderators

And what is className ?

Come on, give us the code we need, not 1 line after the other.

Your code was expecting a table and not a class name as a string.

The error says it got nil instead of a table. So it means the value of className here

setElementData(player, "class", className) 

is nil.

So give us the code above that line !

+ If you want to use a classe name instead of a table of class members, then use this code (based on iAbo's code):

function classchat(player, command, ...) 
    local message = table.concat({...}, " ") 
    for i,v in ipairs(getElementsByType("player")) do 
        if getElementData( player, "class" ) == getElementData( v, "class" )  then 
            outputChatBox("*CLASS*" .. getPlayerName(player) .. ": " .. message , v, 255, 100, 0, true) 
        end 
    end 
end 
addCommandHandler("class", classchat) 

Note (and I repeat) the code will still not work untill you fix the className value for the setElementData

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...