Resetting Variables in a function?

Post Reply
Skriptz
Posts: 45
Joined: Sun Dec 27, 2009 10:48 pm

Resetting Variables in a function?

Post by Skriptz »

I'm trying to run an alias with a function in it called ResetAffs().

In the function I listed every affliction there is equalling 0.
For example
Code: [show] | [select all] lua
function ResetAff()

Sadness = 0
Dementia = 0
Hallucinations = 0
Confusion = 0
Paranoia = 0
Hypersomnia = 0
Hatred = 0
Blood_curse = 0

end
Now when I'm running that function it's not resetting. Is there something I'm missing?

Seinchin
Posts: 9
Joined: Thu Jun 10, 2010 6:10 am

Re: Resetting Variables in a function?

Post by Seinchin »

Maybe post the code where you call the function from. The function looks fine...also make sure the script and the alias are activated.
Last edited by Seinchin on Sat Jun 12, 2010 8:12 am, edited 1 time in total.

Skriptz
Posts: 45
Joined: Sun Dec 27, 2009 10:48 pm

Re: Resetting Variables in a function?

Post by Skriptz »

Seinchin wrote:Did you create an alias or button to actually call the function or are you just typing the function name into the command line? Maybe post the code where you call the function from.
Good idea.
It's an alias called diag
Code: [show] | [select all] lua
	Check.Diag = 1
	
ResetAff()
	send("diag")
		tempTimer( 2, [[ if Check.Diag == 1 then Check.Diag = 0 end ]] )
so when I type Diag it will reset all affs and then changes them based on results. Temp timer is just incase something happens that I haven't planned for and screws it up.

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: Resetting Variables in a function?

Post by Knute »

Another way you could do this is to set up an afflictions table, then manipulate the values in the table.

If you set up the table like this:
Code: [show] | [select all] lua
afflictions = {Sadness = 0,
Dementia = 0,
Hallucinations = 0,
Confusion = 0,
Paranoia = 0,
Hypersomnia = 0,
Hatred = 0,
Blood_curse = 0,}
Then you could set up your function to do:
Code: [show] | [select all] lua
for k,v in pairs(afflictions) do
     afflictions[v] = 0
end
This steps through your table and sets the values to zero.
Since lua puts everything into a table anyway, I figure why not use that to your advantage.

In order to set an affliction, simply set the affliction.Sadness or whatever to 1.
It's actually quite handy once you get used to it. Then, if you want to check on everything at once, just display(afflictions) and it will show the table.

HTH

Post Reply