Jump to content

Decaying Score Script


Motion_Blurz

Recommended Posts

Does anybody have a good reference for script that does a decaying function over time?  Such as for every 1 second 1 point is reduced.  

 

Pretty new to scripting and not sure if this is best serviced as a flag and flag value or something else entirely.  

 

It seems that I can use:

 function trigger.action.setUserFlag(string userFlagName, boolean or number userFlagValue)

to establish an initial value and then run a while loop that reduces flag value over time.  Additionally, I am thinking about having an option that upon event either increases value or further reduces value based upon world events.

 

Thanks in advance!  

Link to comment
Share on other sites

Yeah that won't work at all. 

 

trigger.action.setUserFlag is a function within DCS and you can't and shouldn't try to redefine it, which is what you were doing with it. To call it you just do: 

 

trigger.action.setUserFlag(AlphaFOB, 1)

 

However AlphaFOB isn't actually declared in your code anywhere, so it sees it as trigger.action.setUserFlag(nil, 1), which would fail or just do nothing. 

 

Probably what you were thinking it should be is something like this, but it also has problems:

 

 function decreaseAlphaTickets()
	while(AlphaFOBTickets > 0)do
		trigger.action.outText("Alpha FOB Tickets =", AlphaFOBTickets)
		AlphaFOBTickets = AlphaFOBTickets-1
	end
end

You would have to call that function somewhere for that code to run. Make some trigger that is Repetitive> Time More than 5 seconds> Do script: decreaseAlphaTickets()

 

There are two main problems:

1. It is basically going to decrease all of the tickets instantly the moment it is called. Any loop call like "while condition do" will iterate until the condition is met. Sometimes this can result in an infinite loop, but in this case it'll just count down from 500 to 0 in milliseconds. You should remove the while loop. Either call decreaseAlphaTickets() within a trigger as stated above or use timer.scheduleFunction to constantly set it to occur again. 

2. Your outText function is not formatted correctly and it will error. trigger.action.outText("Alpha FOB Tickets = " .. AlphaFOBTickets, 20) would be the correct format if you wanted to display it for 20 seconds. Commas separate input values while .. will combine strings. Though depending on how often tickets decrease you will end up with a wall of messages. 

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

21 hours ago, Grimes said:

Yeah that won't work at all. 

 

trigger.action.setUserFlag is a function within DCS and you can't and shouldn't try to redefine it, which is what you were doing with it. To call it you just do: 

 

trigger.action.setUserFlag(AlphaFOB, 1)

 

However AlphaFOB isn't actually declared in your code anywhere, so it sees it as trigger.action.setUserFlag(nil, 1), which would fail or just do nothing. 

 

Probably what you were thinking it should be is something like this, but it also has problems:

 

 function decreaseAlphaTickets()
	while(AlphaFOBTickets > 0)do
		trigger.action.outText("Alpha FOB Tickets =", AlphaFOBTickets)
		AlphaFOBTickets = AlphaFOBTickets-1
	end
end

You would have to call that function somewhere for that code to run. Make some trigger that is Repetitive> Time More than 5 seconds> Do script: decreaseAlphaTickets()

 

There are two main problems:

1. It is basically going to decrease all of the tickets instantly the moment it is called. Any loop call like "while condition do" will iterate until the condition is met. Sometimes this can result in an infinite loop, but in this case it'll just count down from 500 to 0 in milliseconds. You should remove the while loop. Either call decreaseAlphaTickets() within a trigger as stated above or use timer.scheduleFunction to constantly set it to occur again. 

2. Your outText function is not formatted correctly and it will error. trigger.action.outText("Alpha FOB Tickets = " .. AlphaFOBTickets, 20) would be the correct format if you wanted to display it for 20 seconds. Commas separate input values while .. will combine strings. Though depending on how often tickets decrease you will end up with a wall of messages. 

Thanks Grimes.  With your input, I was able to get it working.  

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...