Motion_Blurz Posted September 19, 2021 Share Posted September 19, 2021 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 More sharing options...
Motion_Blurz Posted September 19, 2021 Author Share Posted September 19, 2021 (edited) Removed Edited September 19, 2021 by Motion_Blurz Link to comment Share on other sites More sharing options...
Grimes Posted September 19, 2021 Share Posted September 19, 2021 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 Server, Scripting 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 More sharing options...
Motion_Blurz Posted September 20, 2021 Author Share Posted September 20, 2021 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 More sharing options...
Recommended Posts