JeViCo Posted April 6, 2018 Share Posted April 6, 2018 Hello everyone! i met one problem today. I want to change dynamically it text for fuel system. I tried to use guiSetText, onClientRender, etc but got nothing + no info in debug ((( Link to comment
WorthlessCynomys Posted April 6, 2018 Share Posted April 6, 2018 So you want to display the fuel amount in a car? Read the dxDrawText page on WIKI. Here's an example, how to put it in the context. addEventHandler("onClientRender", root, function() -- dxDrawText here end ); 1 Link to comment
Moderators Patrick Posted April 6, 2018 Moderators Share Posted April 6, 2018 Use dxDrawText. It's easier and better. https://wiki.multitheftauto.com/wiki/DxDrawText Link to comment
JeViCo Posted April 6, 2018 Author Share Posted April 6, 2018 Just now, WorthlessCynomys said: So you want to display the fuel amount in a car? Read the dxDrawText page on WIKI. Here's an example, how to put it in the context. addEventHandler("onClientRender", root, function() -- dxDrawText here end ); i know about that but i want to make it within only gui Link to comment
WorthlessCynomys Posted April 6, 2018 Share Posted April 6, 2018 Well... Most of the time I don't mix MTA GUI with dx functions. And tbh I don't really understand your intentions Link to comment
Moderators Patrick Posted April 6, 2018 Moderators Share Posted April 6, 2018 setTimer(function() guiSetText(label, "text") end, 1000, 0) -- refresh, every sec Link to comment
JeViCo Posted April 6, 2018 Author Share Posted April 6, 2018 (edited) setTimer(function() if check then local veh = getPedOccupiedVehicle(localPlayer) -- maxFuel = carFuel[0] if carFuel[getElementModel(veh)] then maxFuel = carFuel[getElementModel(veh)] return end -- curFuel = getElementData(veh,"fuel") if not curFuel then curFuel = 0 end -- fuelType = carEngType[0] if carEngType[getElementModel(veh)] then fuelType = carEngType[getElementModel(veh)] return end guiSetText(desc_memo,"some text") guiSetText(pay_memo,"some text x2") end end, 1000, 0) function getEngState() local veh = getPedOccupiedVehicle(localPlayer) if veh then if not getVehicleEngineState(veh) then check = true setElementData(localPlayer,"refuelling",true) guiSetVisible(mainwind,true) -- show window removeEventHandler("onClientRender",root,getEngState) end end end function onHit(player) veh = getPedOccupiedVehicle(player) if veh then addEventHandler("onClientRender",root,getEngState) end end i gave up i don't even know what's wrong Edited April 6, 2018 by Juuve Link to comment
WorthlessCynomys Posted April 6, 2018 Share Posted April 6, 2018 You never give up. That's a rule if you want to learn this. What should this script do? Do you use debugscript? Have any errors? Link to comment
JeViCo Posted April 7, 2018 Author Share Posted April 7, 2018 21 hours ago, WorthlessCynomys said: You never give up. That's a rule if you want to learn this. What should this script do? Do you use debugscript? Have any errors? i didn't give up/ that was temporary I removed this if carFuel[getElementModel(veh)] then maxFuel = carFuel[getElementModel(veh)] return end and replaced with this maxFuel = carFuel[getElementModel(veh)] and it worked. No errors, no debugscript 3 info and outputChatBox worked properly. Maybe this is MTA bug OR i don't understand RETURN fully. Saw smth about that in other topics Link to comment
myonlake Posted April 7, 2018 Share Posted April 7, 2018 (edited) 1 hour ago, Juuve said: i didn't give up/ that was temporary I removed this if carFuel[getElementModel(veh)] then maxFuel = carFuel[getElementModel(veh)] return end and replaced with this maxFuel = carFuel[getElementModel(veh)] and it worked. No errors, no debugscript 3 info and outputChatBox worked properly. Maybe this is MTA bug OR i don't understand RETURN fully. Saw smth about that in other topics Return will return the value after it to the caller. In this case your "return ... end" actually just stopped executing the rest of the code. if (1 == 1) then return end print "This will never get triggered." An example of how return can be used... local function getAge(name) if (name == "John") then return 30 elseif (name == "Jane") then return 31 end end print("John's age is " .. (getAge "John")) -- Will print John's age is 30 print("Jane's age is " .. (getAge "Jane")) -- Will print Jane's age is 31 print("Jack's age is " .. (getAge "Jack" or "unknown")) -- Will print Jack's age is unknown Edited April 7, 2018 by myonlake 1 Link to comment
JeViCo Posted April 7, 2018 Author Share Posted April 7, 2018 1 hour ago, myonlake said: Return will return the value after it to the caller. In this case your "return ... end" actually just stopped executing the rest of the code. if (1 == 1) then return end print "This will never get triggered." An example of how return can be used... local function getAge(name) if (name == "John") then return 30 elseif (name == "Jane") then return 31 end end print("John's age is " .. (getAge "John")) -- Will print John's age is 30 print("Jane's age is " .. (getAge "Jane")) -- Will print Jane's age is 31 print("Jack's age is " .. (getAge "Jack" or "unknown")) -- Will print Jack's age is unknown thank you very useful Link to comment
myonlake Posted April 7, 2018 Share Posted April 7, 2018 6 minutes ago, Juuve said: thank you very useful You're welcome! 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