Jump to content

how scheduleFunction is supposed to work ?


Recommended Posts

Posted (edited)

I've been trying to do something quite simple for an incredible amount of time.

 

Here's the goal : The group should stop orbiting if flag 1 OR 5 are true.

 

I try (as self-teaching purpose) to this via script and Mist only (no mission editor manipulation).

 

So :

 

function CheckStatus()
affiche("Checking Transit",1)
local flag1 = trigger.misc.getUserFlag(1)
local flag5 = trigger.misc.getUserFlag(5)
if flag1 ~= 0 or flag5 ~= 0 then
	--trigger.action.setUserFlag(6, true)
	local groupGround = Group.getByName('Group Player #002')
	local groupGroundControl = groupGround:getController()
	groupGroundControl.popTask()
	affiche("Flag 1 "..flag1,5)
	affiche("Flag 5 "..flag5,5)
	affiche("Transit initié",5)
else
	return timer.getTime() + 5
end
end

timer.scheduleFunction(CheckStatus,{},timer.getTime() + 5)

 

This is not working. I've trying to use (and modify) the exemple from documentation to no avail.

 

In the log I get :

 

ERROR SCRIPTING: MIST|doScheduledFunctions|1019: Error in scheduled function: $1[string "C:\Users\Arnaud\AppData\Local\Temp\DCS.openbeta\/~mis000036D0.lua"]:5053: attempt to compare nil with number

 

I don't understand where it comes from...

 

How to use scheduleFunction with a function with no arguments ?

 

Am lost....

Edited by Arnaud
Posted (edited)

This is all standard DCS code, you don't need MIST to run it.

 

Anyway, looks like the error is happening in line 5053 of the temporary lua file located in C:\Users\Arnaud\AppData\Local\Temp\DCS.openbeta\/~mis000036D0.lua

 

(Note that DCS creates these temporary files when you run scripted missions, but keep in mind that they're removed eventually)

 

There's a chance this temporary lua file is a copy of mist_4_3_74.lua... if this is the case, then I guess that the problematic line is the following:

if [color="Red"]messageData.displayedFor[/color] > messageData.displayTime then

[color="Blue"]-- If [i][b]messageData.displayedFor[/b][/i] returns nil, this statement will raise the kind of error that you got[/color]

 

This error seems to be related to text messages, which brings me to something I've seen in your snippet:

[color="Red"]affiche[/color]("Checking Transit",1)
[color="Red"]affiche[/color]("Flag 1 "..flag1,5)
[color="red"]affiche[/color]("Flag 5 "..flag5,5)
[color="red"]affiche[/color]("Transit initié",5)
[color="Blue"]-- Looks like you're trying to create text messages using a variable / function named [i][b]affiche[/b][/i], which isn't defined in your snippet[/color]

[color="Blue"]-- Is affiche defined somewhere else, like this?[/color]
function affiche(text, time) 
  trigger.action.outText(text , time)
end

 

 

 

 

Here, try this snippet instead, see if you still get that error (MIST isn't needed):

 

function affiche(text, time) 
  trigger.action.outText(text , time)
end

function CheckStatus()
 
 affiche("Checking Transit",1)
 
 local flag1 = trigger.misc.getUserFlag("1")  [color="Blue"]-- Give flag name as string instead of number, just in case[/color]
 local flag5 = trigger.misc.getUserFlag("5")  [color="blue"]-- Give flag name as string instead of number, just in case[/color]
 
 if (flag1 == 1 or flag5 == 1) and Group.getByName('Group Player #002') then [color="blue"]-- When flags are true (on), they have a value of 1, also, it's always a good idea to make sure the group is present[/color]
   
    if Group.getByName('Group Player #002'):isExist() then [color="blue"]-- Check that the group exists before trying to do stuff with it[/color]
   
       local groupGround = Group.getByName('Group Player #002')
       local groupGroundControl = groupGround:getController()
       
       groupGroundControl[color="Green"]:[/color]popTask() [color="Blue"]-- Use colon instead of dot[/color]
       
      if flag1 then   [color="Blue"]-- Make sure that flag1 isn't nil before trying to concatenate it in a message[/color]
         affiche("Flag 1 "..flag1,5)
      end 
      
      if flag5 then  [color="Blue"]-- Make sure that flag5 isn't nil before trying to concatenate it in a message[/color]
         affiche("Flag 5 "..flag5,5)
      end 
      
       affiche("Transit initié",5)
    end
  end  
 
 if flag1 ~= 1 or flag5 ~= 1 then  [color="Blue"]-- The scheduler will keep running unless both flags are true[/color]
     return timer.getTime() + 5 
 
 end
end

timer.scheduleFunction(CheckStatus, nil ,timer.getTime() + 5) [color="Blue"]-- If you don't have to pass any arguments, just pass nil[/color]

 

Edited by Hardcard
Posted (edited)

Thank's HardCard you helped me a lot here ! :notworthy:

 

My Display/tracing function :

 

local function affiche(mess, temps)
trigger.action.outText(mess, temps , true)
end

 

And my function to initiate the next step of the flight (that's orbiting)

 

function CheckTransit()
affiche("Checking Transit",1)
local flag1 = trigger.misc.getUserFlag(1)
local flag5 = trigger.misc.getUserFlag(5)
if (flag1 == 1 or flag5 == 1) and  Group.getByName('Group Player #002') then
	if Group.getByName('Group Player #002'):isExist() then
		Group.getByName('Group Player #002'):getController():popTask()
		affiche("Transit initié",2)
	end
else
	return timer.getTime() + 5
end
end

 

I know it's not precisely what you told me but I was eager to test a few new things.

And the call to the function

 

timer.scheduleFunction(CheckTransit, nil, timer.getTime()+5)

 

Now it runs normally without any error.

I can read the trace displaying each 5 seconds and once one flag is set to True I can see my control messages displaying.

 

But

 

The group is still orbiting, no matter what... :blink:

 

Also I tried to test eventHandler with this :

 

local function listFlags(taille)
for v = 1, taille, 1 do
	affiche("Mon flag "..v.." = " .. trigger.misc.getUserFlag(v),1)
end
end

local function displayFlags(event) 
  if event.id == world.event.S_EVENT_DEAD and event.initiator then 
   affiche("Unité "..event.initiator:getName().." détruite", 1)
   listFlags(10)
  end 
end 
mist.addEventHandler(displayFlags)

 

It used to work, but now it doesn't anymore. Maybe there is a conflict between eventhandlers and scheduleFunction ?

 

So frustrating....

Edited by Arnaud
Posted

Hi Arnaud

 

There s no pb using timer functions and events handler. If you want information write me in MP in french. But you can do that withput mist too.

 

Sunski

Posted

Hi Arnaud,

Sorry to come here after the battle is over ^^

If you ever need french-speaking help with mission editing, feel free to drop to the VEAF's discord or forum. I'm often here, and always eager to help !

Zip - VEAF :pilotfly:

 

If you want to learn, talk and fly with french-speaking friends, the Virtual European Air Force is here for you ! Meet us on our Discord and our forum

If you're a mission creator, you may want to check the VEAF Mission Creation Tools (and its GitHub repository) a set of open-source scripts and tools that make creating a dynamic mission a breeze !

  • Recently Browsing   0 members

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