jkub Posted August 23, 2009 Share Posted August 23, 2009 I am working on a simple Gui menu for editing headlight colors. I think my problem is that im not passing the data from the client to the server correctly. I got buttons for common colors and I got text fields so you can make your own color. I use guiGetText to get whatever is in the text fields. Here is some code im using Here is a client side method I tried function selectCustom () r = guiGetText ( cstFieldRd ) g = guiGetText ( cstFieldGrn ) b = guiGetText ( cstFieldBlu ) triggerServerEvent ( "clientCustom", getRootElement(), r, g, b ) end Here is another client method I tried function selectCustom () triggerServerEvent ( "clientCustom", getRootElement(), guiGetText(cstFieldRed), guiGetText(cstFieldGreen), guiGetText(cstFieldBlue) ) end Here is a server method I tried to recieve the data addEventHandler ( "clientCustom", getRootElement(), function ( red, green, blue ) clientVeh = getPedOccupiedVehicle ( client ) setVehicleHeadLightColor ( clientVeh, red, green, blue ) end ) I thought that when you pass data from client to server using triggerServerEvent that whatever element or argument you pass will automaticly be one of the arguments inside the function ( ) Can you help me please? Link to comment
50p Posted August 23, 2009 Share Posted August 23, 2009 Don't you get any errors or warnings? Both of your tries are correct but from what I see, you use string in the setVehicleHeadLightColor. Use tonumber() to convert string to number. Also, make sure that your clientCustom event is added server-side. Link to comment
jkub Posted August 24, 2009 Author Share Posted August 24, 2009 Is this what you meanVV addEventHandler ( "clientCustom", getRootElement(), function ( red, green, blue ) clientVeh = getPedOccupiedVehicle ( client ) setVehicleHeadLightColor ( clientVeh, tonumber(red), tonumber(green), tonumber(blue) ) end ) Ive tried that^^ and does not work... that way and the way I had before that gives the same error in the debug saying that my setVehicleHeadLightColor is a bad argument Link to comment
50p Posted August 24, 2009 Share Posted August 24, 2009 After you getPedOccupiedVehicle(), use outputChatBox or outputDebugString to see what clientVeh is. If it's "userdata" then it's correct. If not, then you're not in vehicle. Then outputChatbox or outputDebugString to see what each color variable is, like: outputChatBox( "colors from client: ".. red ..", ".. green ..", ".. blue ); Link to comment
Lordy Posted August 24, 2009 Share Posted August 24, 2009 (edited) Also you haven't told us what the that way and the way I had before that gives the same error in the debug error is.Edit: damn next time I'll read the last row as well. Edited August 25, 2009 by Guest Link to comment
50p Posted August 24, 2009 Share Posted August 24, 2009 Also you haven't told us what the that way and the way I had before that gives the same error in the debug error is. that way and the way I had before that gives the same error in the debugsaying that my setVehicleHeadLightColor is a bad argument Link to comment
jkub Posted August 25, 2009 Author Share Posted August 25, 2009 it says userdata but I used triggerClientEvent from the server I used an example from the wiki and altered the data to suit what I was trying to do. Link to comment
jkub Posted August 25, 2009 Author Share Posted August 25, 2009 Yes I did and it said attempt to concatenate number values Link to comment
50p Posted August 25, 2009 Share Posted August 25, 2009 You need to debug it. outputDebugString or outputChatbox, for everything that may be causing these warnings. If you get "bar argument" for any of these 2 functions, use tostring() function to convert variables to string. As you get "attempt to concatenate number values" it means you try to concatenate number with string, like this: "this is string which wants number: " .. 123 . As I said, debug every variable (output them to chatbox or debug window). Link to comment
jkub Posted August 25, 2009 Author Share Posted August 25, 2009 I used outputChatBox and tostring to show what I had for clientVehicle and the three custom color values for clientvehicle it said "userdata: 000000F4" and for all three color values it said "false" Link to comment
50p Posted August 26, 2009 Share Posted August 26, 2009 So do you know which arguments are bad now? As I said, "userdata" is OK but the colours are not. Before you send the colour values to the server (triggerServerEvent) make sure the values are numbers (in the client-side script) with the same method (tostring() and outputChatBox) Link to comment
jkub Posted August 26, 2009 Author Share Posted August 26, 2009 I did that outputChatBox on the client side and it also said "false" x3 for my color values. Link to comment
Remp Posted August 26, 2009 Share Posted August 26, 2009 if we look at the wiki page for guiGetText we can see this for the return values: Returns a string containing the requested element's text, or false if the gui element passed to the function is invalid. so this must mean that you are passing an invalid gui element make sure cstFieldRd, cstFieldGrn and cstFieldBlu all exist (or that you havent just mistyped the variable names) Link to comment
jkub Posted August 26, 2009 Author Share Posted August 26, 2009 Everything is wrote down correct no typos. But 50p >> When I made this I did with the help of gui-classes. I used the :AddTextBox custom function made for it. Some odd reason when I replaced that function with the original function guiCreateEdit... It worked. Is there a special way to make it work using gui-classes? Link to comment
50p Posted August 26, 2009 Share Posted August 26, 2009 Everything is wrote down correct no typos. But 50p >> When I made this I did with the help of gui-classes. I used the :AddTextBox custom function made for it. Some odd reason when I replaced that function with the original function guiCreateEdit... It worked. Is there a special way to make it work using gui-classes? You can use shared member functions. That is https://wiki.multitheftauto.com/index.ph ... ll_classes Use :Text() to get the text form the text box, label, window, etc. Link to comment
jkub Posted August 26, 2009 Author Share Posted August 26, 2009 Wow I never knew about that. I guess ill take a look at it later:) 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