iPot Posted May 4, 2012 Share Posted May 4, 2012 Should I use AddEvent/AddEventHandler here? Or are there other options. Like in GTA SA scripting you could just type JUMP @label. then I could use JUMP @otherFunction. It's not like that but that's why I came here, to ask. function testFunction testvariable = getTestData(aDude) if (testvariable == true) then -- go to otherFunction end end function otherFunction -- blablabla end bindKey(fire,both,testFunction) Already thanks. iPot PS: Nice tabbing for a newb huh? Link to comment
Michael# Posted May 4, 2012 Share Posted May 4, 2012 -- we declare a vector ( table ) local aTest = { -- we create index 'username' and 'password' and set his value [ 'username' ] = 'Jayz'; [ 'password' ] = 123456; } -- we declare a function function dTestFunction ( ) -- now we call function 'getTestData' and pass aTest vector and we allocate the return value in a var local vTest = getTestData ( aTest, 'Jayz', 123456 ) -- if vTest return true if ( vTest ) then -- call function 'otherFunction' otherFunction ( ) end end function getTestData ( aVector, user, password ) -- check if passed parameter aVector is a table if ( type ( aVector ) == 'table' ) then -- check if table user and pass are the same as parameters passed if ( aVector['username'] == tostring ( user ) and aVector['password'] == tonumber ( password ) ) then return true -- else do that else return false end -- if it's not a table do that else return false end -- end function declaration end function otherFunction ( ) -- prints Welcome on the screen ( print function don't work on MTA! ) -- _G['print'] ( 'Welcome' ) = print ( 'Welcome' ) _G['print'] ( 'Welcome' ) end -- bindKey ( 'fire', 'both', dTestFunction ) If you don't understand something just tell me. This answer your question, I think. So, you can call functions by just typing: theFunction ( parameters separated by comma ) If there are any errors, please tell me. Link to comment
iPot Posted May 4, 2012 Author Share Posted May 4, 2012 Thank you very much It works perfectly, where is the tutorial that explains the part I missed apparently? In theory this loop should work but it doesn't. How come? I defined variable2 and thePlayer btw. function testFunction() local variable = getVar(thePlayer) outputChatBox("Debug message",thePlayer) if (variable == 0 ) then if (variable2 == false) then outputChatBox("Debug message",thePlayer) takeAction() testFunction2() end end end function testFunction2() local variable = getVar(thePlayer) if (variable ~= 0) then outputChatBox("Debug message",thePlayer) takeAction2() testFunction() end function takeAction() -- Do things. testFunction() end function takeAction2() -- Do different things. testFunction() end addCommandHandler("command", testFunction) EDIT: I don't even get the first debug message in testFunction() Link to comment
Jaysds1 Posted May 4, 2012 Share Posted May 4, 2012 (edited) here: function testFunction(thePlayer,command) --You forgot the variables local variable = getVar(thePlayer) outputChatBox("Debug message",thePlayer) if (variable == 0 ) then if (variable2 == false) then outputChatBox("Debug message",thePlayer) takeAction() testFunction2() end end end function testFunction2() local variable = getVar(thePlayer) if (variable ~= 0) then outputChatBox("Debug message",thePlayer) takeAction2() testFunction() end end function takeAction() -- Do things. testFunction() end function takeAction2() -- Do different things. testFunction() end addCommandHandler("command", testFunction) EDIT: I found my mistake, Copy again Edited May 4, 2012 by Guest Link to comment
iPot Posted May 4, 2012 Author Share Posted May 4, 2012 Nope, doesn't change a thing. Like I expected. I used previous addCommandHandlers and functions (very basic ones) but with the same variables and it worked perfectly. Link to comment
Jaysds1 Posted May 4, 2012 Share Posted May 4, 2012 So, you already solved the issue? BTW, What's "getVar"? Link to comment
iPot Posted May 4, 2012 Author Share Posted May 4, 2012 It's a example built-in function. Like getPlayerName etc.. No didn't solve it. EDIT: Fixed. 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