Ulysses

General => Developers Corner => Topic started by: StaTiiKxKALEB on April 19, 2016, 10:22:13 PM

Title: ulx.fancyLogAdmin ran multiple times
Post by: StaTiiKxKALEB on April 19, 2016, 10:22:13 PM
I was messing around because I want to learn lua, I want it so if the target_plys is greater than 1 it prints something else than if it was 1. I know why the fancylog is ran multiple times. It runs multiple times because it runs once for each consecutive player. How would I make it where it only prints it once?
 
Code: [Select]
function ulx.test( calling_ply, target_plys, amount )
local prevhp2 = target_plys[1]:Health()

for i=1, #target_plys do
target_plys[ i ]:SetHealth(amount)

if #target_plys > 1 then
ulx.fancyLogAdmin( calling_ply, "#A set the HP of #T to #s", target_plys, amount )
else
ulx.fancyLogAdmin( calling_ply, "#A set the HP of #T to #s (it was previously #s)", target_plys, amount, prevhp2)
end
end
end
local test = ulx.command( CATEGORY_NAME, "ulx test", ulx.test, "!test", true )
test:addParam{ type=ULib.cmds.PlayersArg }
test:addParam{ type=ULib.cmds.NumArg }
test:defaultAccess( ULib.ACCESS_ADMIN )
test:help( "Test." )
Title: Re: ulx.fancyLogAdmin ran multiple times
Post by: Caustic Soda-Senpai on April 20, 2016, 12:13:57 AM
You place the fancylog after the loop.
Title: Re: ulx.fancyLogAdmin ran multiple times
Post by: StaTiiKxKALEB on April 20, 2016, 12:37:18 AM
If I place it after the loop, prevhp2 returns nil.
Title: Re: ulx.fancyLogAdmin ran multiple times
Post by: Buzzkill on April 20, 2016, 05:45:22 AM
Code: [Select]
function ulx.test( calling_ply, target_plys, amount )
local prevhp2 = target_plys[1]:Health()

for i=1, #target_plys do
target_plys[ i ]:SetHealth(amount)
end

        if #target_plys > 1 then
ulx.fancyLogAdmin( calling_ply, "#A set the HP of #T to #s", target_plys, amount )
else
ulx.fancyLogAdmin( calling_ply, "#A set the HP of #T to #s (it was previously #s)", target_plys, amount, prevhp2)
end
end
local test = ulx.command( CATEGORY_NAME, "ulx test", ulx.test, "!test", true )
test:addParam{ type=ULib.cmds.PlayersArg }


You're saying the above shows nil for prevhp2?
Title: Re: ulx.fancyLogAdmin ran multiple times
Post by: StaTiiKxKALEB on April 21, 2016, 01:50:23 PM
It showed nil when I tried that before, I fixed it I forgot to reply since I was not home for the past few days. Not sure why it would be nil in the first place. I might have misspelled something on accident.