Jump to content

additional variables to addEventHandler


Elohim

Recommended Posts

Posted

Hello, i want to do an function that triggers other dx function, like this:

local sw,sh = guiGetScreenSize() 
function draw(splashpath,name,text) 
  if (splashpath) and (name) and (text) then 
dg =  dxDrawImage(sw*.1,sh*.65,sw*.900,sh*.600,"tt.png") 
nm =  dxDrawText(name,sw*.3,sh*.85) 
spl = dxDrawImage(sw*.12,sh*.72,sw*.200,sh*.400,splashpath) 
txt =  dxDrawText(text,sw*.29,sh*.90) 
else 
  outputDebugScript("Incorrect Syntaxis: drawDialogue(splashartpath,name,text)") 
end 
end 
--This triggers the function in top 
function drawDialogue(splashpath,name,text) 
  addEventHandler("onClientRender",getLocalPlayer(),draw) 
end 

i dont know how to add the arguments splashpath,name, and text into the eventHandler

Posted

Just make them global variables I guess.

Then the drawDialogue function would not just start the rendering but also do the checks and set the values.

Posted

Oh, ok, and what is the best way to render that? "onClientRender"?

Edit: sorry, i cant get it to work, how can i do correctly the global variables? only add the _ ?

Posted

They best way would probably be to put them the same way as you put the "local sw,sh" variables.

They are available in the whole script file, as long as they are outside of a function.

Without the "local" they would be available in every script file e.g. all client-side scripts, of the resource.

http://lua-users.org/wiki/ScopeTutorial

Posted

I did this

local sw,sh = guiGetScreenSize() 
local spacer = dxGetFontHeight(1.2,"default") 
local nm = nm 
local spl = spl 
local txt = txt 
function draw(splashpath,name,text) 
  if (splashpath) and (name) and (text) then 
dg =  dxDrawImage(sw*.1,sh*.65,sw*.900,sh*.600,"tt.png") 
nm =  dxDrawText(name,sw*.3,sh*.85) 
spl = dxDrawImage(sw*.12,sh*.72,sw*.200,sh*.400,splashpath) 
txt =  dxDrawText(text,sw*.29,sh*.90+spacer) 
else 
  outputDebugScript("Incorrect Syntaxis: drawDialogue(splashartpath,name,text)") 
end 
end 
  
function drawDialogue(splashpath,name,text) 
  local nm = "bartender" 
  local spl = "bartender.png" 
  local txt = "test" 
  addEventHandler("onClientRender",getLocalPlayer(),draw) 
end 

didnt work, i think i did a mistake anywhere, or everywhere u.u

Posted

You might need to go through the basics again.

Those dx functions don't return anything useful.

local nm = nm 

That seems kinda wrong too.

And the rest.. remove the if else from the render function and put that in the other one for the start.

Posted
  
local sw,sh = guiGetScreenSize() 
local spacer = dxGetFontHeight(1.2,"default") 
function draw(splashpath,name,text) 
local dg =  dxDrawImage(sw*.1,sh*.65,sw*.900,sh*.600,"tt.png") 
local nm =  dxDrawText(name,sw*.3,sh*.85) 
local spl = dxDrawImage(sw*.12,sh*.72,sw*.200,sh*.400,splashpath) 
local txt =  dxDrawText(text,sw*.29,sh*.90+spacer) 
end 
  
function drawDialogue(splashpath,name,text) 
  local nm = "bartender" 
  local spl = "bartender.png" 
  local txt = "test" 
  addEventHandler("onClientRender",root,draw) 
end 
  
drawDialogue("bartender.png","bartender","testing the shoots") 
  
  
  

i removed the locals on top, and repaired the errors that anubhav wrote, but i still cant add the variables to the event

Posted
  
local sw,sh = guiGetScreenSize() 
local spacer = dxGetFontHeight(1.2,"default") 
local name = "" 
local splashpath = "" 
local text = "" 
  
function draw(splashpath,text) 
    local dg =  dxDrawImage(sw*.1,sh*.65,sw*.900,sh*.600,"tt.png") 
    local nm =  dxDrawText(name,sw*.3,sh*.85) 
    local spl = dxDrawImage(sw*.12,sh*.72,sw*.200,sh*.400,splashpath) 
    local txt =  dxDrawText(text,sw*.29,sh*.90+spacer) 
end 
  
function drawDialogue(splashpath,name,text) 
    name = "bartender" 
    splashpath = "bartender.png" 
    text = "test" 
     
    addEventHandler("onClientRender",root,draw) 
end 
  
drawDialogue("bartender.png","bartender","testing the shoots") 
  

Posted
  
local sw,sh = guiGetScreenSize() 
local spacer = dxGetFontHeight(1.2,"default") 
local name = "" 
local splashpath = "" 
local text = "" 
  
function draw() 
    local dg =  dxDrawImage(sw*.1,sh*.65,sw*.900,sh*.600,"tt.png") 
    local nm =  dxDrawText(name,sw*.3,sh*.85) 
    local spl = dxDrawImage(sw*.12,sh*.72,sw*.200,sh*.400,splashpath) 
    local txt =  dxDrawText(text,sw*.29,sh*.90+spacer) 
end 
  
function drawDialogue(splashpath,name,text) 
    name = "bartender" 
    splashpath = "bartender.png" 
    text = "test" 
  
    addEventHandler("onClientRender",root,draw) 
end 
  
drawDialogue("bartender.png","bartender","testing the shoots") 
  

Posted

Line 10:

    local nm =  dxDrawText(name,sw*.3,sh*.85) 

I don't see any image path or function which should draw the image. Send us a screenshot of your debug script mode 3, that'll be helpful I guess.

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