Jump to content

Parameters Being Passed Arrays


Cyanide

Recommended Posts

How exactly can arrays be used with parameters in functions? This code:

function returnProfileInformation( name, value ) 
    outputChatBox( name ) 
    outputChatBox( value ) 
    Profile_Data[ name ] = value 
    outputChatBox( "I have been called!" )  
end 

is a example of what I'm trying to do. The parameter name is "Cyanide", and the other parameter is "44". From my debug, line 5 isn't being called because line 4 cancels the event.

Link to comment

It's being cancelled(Stops because of an error) Because you didn't declare Profile_Data as a table like this:

function returnProfileInformation( name, value ) 
    outputChatBox( name ) 
    outputChatBox( value ) 
    Profile_Data = {} 
    Profile_Data[ name ] = value 
    outputChatBox( "I have been called!" ) 
end 

If you want to define a table use this:

 theTable = {} 

Link to comment

I wont post the whole code, here's it broken down into important snippets.

  
local 
    Profile_Window, 
    Profile_Cancel, 
    Profile_Search, 
    Profile_Label, 
    Profile_image, 
    Profile_SearchB, 
    Profile_ShowProfile, 
    Profile_ShowProfile_Label, 
    Profile_ShowProfile_Avatar, 
    Profile_ShowProfile_Like, 
    Profile_ShowProfile_Cancel, 
    Profile_Data = { } 
  
-- code 
  
function returnProfileInformation( name, value ) 
    outputChatBox( name ) 
    outputChatBox( value ) 
    Profile_Data[ name ] = value 
    outputChatBox( "I have been called!" )  
end 
  

Link to comment

Try this:

local Profile_Window 
    local Profile_Cancel 
    local Profile_Search 
    local Profile_Label 
    local Profile_image 
    local Profile_SearchB 
    local Profile_ShowProfile 
    local Profile_ShowProfile_Label 
    local Profile_ShowProfile_Avatar 
    local Profile_ShowProfile_Like 
    local Profile_ShowProfile_Cancel 
    local Profile_Data = { } 
-- code 
  
function returnProfileInformation( name, value ) 
    outputChatBox( name ) 
    outputChatBox( value ) 
    Profile_Data[ name ] = value 
    outputChatBox( "I have been called!" ) 
end 

Link to comment

Thanks alot, it's fixed now. But why did it only work when I put local behind all variables I wanted to create. I was able to function properly without them before until now.

Also, the fix caused another problem where returnProfileInformation isn't being called anymore, and a error prints in console

attempt to index field '?' (a nil value)
. The line of this code is located in another LUA file that calls the client function, so that can be a explanation why it isn't being called. The code for the server LUA is below:
  
function getProfileInfo( name, selection ) 
    local 
        returnValue 
  
    returnValue = executeSQLSelect ( "profiles", selection, "username = '" .. name .. "'", 1) 
    triggerClientEvent ( "returnProfileInformation", getRootElement(), name, returnValue[ 1 ][selection] ) 
end 

The line is located in triggerClientEvent. The code used to work until I used the updated code in your post. This caused a problem before, any clue?

Link to comment
I wont post the whole code, here's it broken down into important snippets.
  
local 
    Profile_Window, 
    Profile_Cancel, 
    Profile_Search, 
    Profile_Label, 
    Profile_image, 
    Profile_SearchB, 
    Profile_ShowProfile, 
    Profile_ShowProfile_Label, 
    Profile_ShowProfile_Avatar, 
    Profile_ShowProfile_Like, 
    Profile_ShowProfile_Cancel, 
    Profile_Data = { } 
  
-- code 
  
function returnProfileInformation( name, value ) 
    outputChatBox( name ) 
    outputChatBox( value ) 
    Profile_Data[ name ] = value 
    outputChatBox( "I have been called!" )  
end 
  

with this code you are creating a table that is stored in Profile_Window variable and the rest (including Profile_Data) are nil.

-- if you use commas like:  
local a, b, c, d =  
  
-- you should provide the values accordingly:  
local a, b, c, d = "string goes in a", 2, "c", {"this table goes into d variable"} 
  

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...