Cyanide Posted July 15, 2011 Share Posted July 15, 2011 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
Jason_Gregory Posted July 15, 2011 Share Posted July 15, 2011 Simple question, does the Array Profil_Data exists ? And what do you exactly mean by canceling the event ? The debugscript should print a message if the Array cannot be filled, with your Parameter. Link to comment
Cyanide Posted July 15, 2011 Author Share Posted July 15, 2011 Yes it is created, debugscript 3 is enabled also. The function cancels (stops) when the array is attempted to be set. Link to comment
JR10 Posted July 15, 2011 Share Posted July 15, 2011 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
Cyanide Posted July 15, 2011 Author Share Posted July 15, 2011 (edited) I did use that, Profile_Data is defined as a array/table, exactly how you created it in your code. Edited July 15, 2011 by Guest Link to comment
Cyanide Posted July 15, 2011 Author Share Posted July 15, 2011 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
JR10 Posted July 16, 2011 Share Posted July 16, 2011 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
Cyanide Posted July 16, 2011 Author Share Posted July 16, 2011 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
Aibo Posted July 16, 2011 Share Posted July 16, 2011 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
Cyanide Posted July 16, 2011 Author Share Posted July 16, 2011 @Aibo - Great! Thanks for the explanation. I seem to be a bit PAWN stiff. Edit: The problem has been solved. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now