Jump to content

guiSetText + memo


JeViCo

Recommended Posts

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 xD

Link to comment
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 :sad: i don't even know what's wrong

Edited by Juuve
Link to comment
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 xD

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
1 hour ago, Juuve said:

i didn't give up/ that was temporary xD

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 by myonlake
  • Thanks 1
Link to comment
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 :D very useful

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