Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dcs.action.DoScript error #179

Open
jeremymoran opened this issue Aug 20, 2021 · 4 comments
Open

dcs.action.DoScript error #179

jeremymoran opened this issue Aug 20, 2021 · 4 comments

Comments

@jeremymoran
Copy link

jeremymoran commented Aug 20, 2021

Hi,

Trying to execute a simple MIST script to respawn aircraft. I have successfully loaded the MIST.lua at mission start. However when I want to execute using the DoScript function, in DCS I get a "DictKey_Translation_7" in the text box.

Python script:

def respawn_trigger(m,groupName):
    lua_script =  "if not Group.getByName('"+groupName+"') then \
                       mist.respawnGroup('"+groupName+"', true) \
                     end"
    trig_respawn = dcs.triggers.TriggerContinious(dcs.triggers.Event.NoEvent, comment='respawn '+groupName)
    trig_respawn.add_action(dcs.action.DoScript(m.string(lua_script)))
    m.triggerrules.triggers.append(trig_respawn)

The end result in DCS is a "DictKey_Translation_7" as the text for the DoScript action.

Also, for more info. Here is my dictionary file from the .miz. I am only calling the respawn_trigger function once, however there are two DictKeys in the file?

dictionary=
{
	["DictKey_Translation_1"]="",
	["DictKey_Translation_2"]="",
	["DictKey_Translation_3"]="",
	["DictKey_Translation_4"]="",
	["DictKey_Translation_6"]="Excellent job!\
Intelligence reports the convoy was destroyed!\
RTB",
	["DictKey_Translation_7"]="if not Group.getByName('USSR CAP 1') then\
   mist.respawnGroup('USSR CAP 1', true)\
end",
	["DictKey_Translation_8"]="if not Group.getByName('USSR CAP 1') then\
   mist.respawnGroup('USSR CAP 1', true)\
end"
}
@jeremymoran
Copy link
Author

Okay, discovered the error. Don't use the m.string function. String needs to be a literal string for it to work correctly.

def respawn_trigger(m,groupName):
    lua_script =  f"if not Group.getByName('"+groupName+"') then\n   mist.respawnGroup('"+groupName+"', true)\nend"
    trig_respawn = dcs.triggers.TriggerContinious(comment='respawn '+groupName)
    trig_respawn.actions.append(dcs.action.DoScript(String(lua_script)))
    m.triggerrules.triggers.append(trig_respawn)

@DanAlbert
Copy link
Collaborator

I think the type annotation (and therefore the default constructor) are probably wrong and this is supposed to be str and not String? Most of pydcs doesn't need (or often support) the translation key String type any more.

def __init__(self, text: String = String()) -> None:

You changing from m.string to String() is doing effectively that. The first argument to the String constructor is an ID, not the content.

@jeremymoran
Copy link
Author

I think the type annotation (and therefore the default constructor) are probably wrong and this is supposed to be str and not String? Most of pydcs doesn't need (or often support) the translation key String type any more.

def __init__(self, text: String = String()) -> None:

You changing from m.string to String() is doing effectively that. The first argument to the String constructor is an ID, not the content.

Yes that was part of the issue as well. I tried String() earlier and it still didn't work.

@DanAlbert
Copy link
Collaborator

Worth reopening to get the default fixed IMO. I don't have those powers :)

@rp- rp- reopened this Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants