Jump to content

Moving string from function to function


kPkPT

Recommended Posts

Hey guys,

so i got two functions, and i want it to be that when i call the first one with a string as an argument, that one calls the second one with the same string. That is not happening, the string the second one receives is "16" or "17" always. Here's the code

function animateDX(text)
	w1 = w1 -10
	dxDrawRectangle(w1, screenH * 0.7898, screenW * 0.1224, screenH * 0.1083, tocolor(35, 35, 35, 255), false)
	addEventHandler("onClientPreRender",getRootElement(),animateDX)
	if(w1 < (screenW * 0.8776)) then
		dxText(text)
		removeEventHandler("onClientPreRender",getRootElement(),animateDX)
	end
end
animateDX("Information")


function dxText(text)
	dxDrawRectangle(screenW * 0.8776, screenH * 0.7898, screenW * 0.1224, screenH * 0.1083, tocolor(35, 35, 35, 255), false)
	dxDrawText("Info", screenW * 0.8953, screenH * 0.7898, screenW * 0.9807, screenH * 0.8093, tocolor(43, 155, 21, 255), 1.00, "bankgothic", "center", "center", false, true, false, false, false)
	dxDrawText(text, screenW * 0.8927, screenH * 0.8185, screenW * 0.9859, screenH * 0.8759, tocolor(254, 255, 255, 255), 1.25, "sans", "center", "top", false, true, false, false, false)
	addEventHandler("onClientPreRender",getRootElement(),dxText)
	setTimer(function() removeEventHandler("onClientPreRender",root,dxText) end,5000,1) 
	
end

 

Link to comment
  • Moderators

 

You can do it like this:

local animateDXInformation = "Information"

function animateDX(text)
  	local text = animateDXInformation

	w1 = w1 - 10
	dxDrawRectangle(w1, screenH * 0.7898, screenW * 0.1224, screenH * 0.1083, tocolor(35, 35, 35, 255), false)
	
	if(w1 < (screenW * 0.8776)) then
		enableDxText(text)
		removeEventHandler("onClientPreRender",getRootElement(),animateDX)
	end
end

addEventHandler("onClientPreRender",getRootElement(),animateDX)


function dxText()
  	local text = animateDXInformation
	dxDrawRectangle(screenW * 0.8776, screenH * 0.7898, screenW * 0.1224, screenH * 0.1083, tocolor(35, 35, 35, 255), false)
	dxDrawText("Info", screenW * 0.8953, screenH * 0.7898, screenW * 0.9807, screenH * 0.8093, tocolor(43, 155, 21, 255), 1.00, "bankgothic", "center", "center", false, true, false, false, false)
	dxDrawText(text, screenW * 0.8927, screenH * 0.8185, screenW * 0.9859, screenH * 0.8759, tocolor(254, 255, 255, 255), 1.25, "sans", "center", "top", false, true, false, false, false)
end

function enableDxText ()
	addEventHandler("onClientPreRender",getRootElement(),dxText)
	setTimer(function() removeEventHandler("onClientPreRender",root,dxText) end,5000,1) 
end

 

You will need to use variables outside of the function for that.

 

 

Link to comment

Okay so i got this now:

addEvent("animateDX",true)
function animateDX(message)
	if(w1 > (screenW * 0.8776)) then
	w1 = w1 -10
	dxDrawRectangle(w1, screenH * 0.7898, screenW * 0.1224, screenH * 0.1083, tocolor(35, 35, 35, 255), false)
	addEventHandler("onClientPreRender",getRootElement(),animateDX)
	end
	if(w1 <= (screenW * 0.8776)) then
		dxDrawRectangle(screenW * 0.8776, screenH * 0.7898, screenW * 0.1224, screenH * 0.1083, tocolor(35, 35, 35, 255), false)
		dxDrawText("Info", screenW * 0.8953, screenH * 0.7898, screenW * 0.9807, screenH * 0.8093, tocolor(43, 155, 21, 255), 1.00, "bankgothic", "center", "center", false, true, false, false, false)
		dxDrawText(message, screenW * 0.8927, screenH * 0.8185, screenW * 0.9859, screenH * 0.8759, tocolor(254, 255, 255, 255), 1.25, "sans", "center", "top", false, true, false, false, false)
		setTimer(function() removeEventHandler("onClientPreRender",root,animateDX) end,5000,1) 
	end
end
addEventHandler("animateDX",root,animateDX)

Still does not work. If i try to call animateDX("something") for example it won't show "something" in the dxDrawText. WHy?

Link to comment
  • Moderators

When executing dx functions, it will render the result for ONE frame. In order to keep showing the result, you have to attach an addEventHandler that triggers on 'onClientRender", which will execute the code every frame.

 

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