这是 GMS 3.X 这个问题的扩展:
从本质上讲,下面的答案对于 GMS 3 也是正确的,但仅限于其 3.2 版(也许 GMS 3.1.2 也是如此)。
正如 KEVIVI 在对答案的评论中指出的那样,早期版本的 GMS 3 有一个错误。
但是,有一个变通的解决方案,它稍微复杂:
Class myDLG : UIframe
{
myDLG(object self) result("\n Create DLG")
~myDLG(object self) result("\n Kill DLG")
void DeferredClose( object self )
{
TagGroup tgs = GetPersistentTagGroup()
number scriptID
if ( tgs.TagGroupGetTagAsLong( "DummyTag_CloseWindow_ID", scriptID ) )
{
object obj = GetScriptObjectFromID( scriptID )
if ( obj.ScriptObjectIsValid() )
{
obj.GetFrameWindow().WindowClose(0)
return
}
}
Debug( "\n Sorry, but could not close dialog." )
}
void CloseButtonAction( object self )
{
// Normally, it would be save to use "self.close()" here,
// but due to a bug, this is currenlty not possible in GMS 3.1
// The alternative method of getting the window of the UIframe object
// and closing it, is okay, but it must not be called directly here,
// or it will crash DM.
// As a work-around, one can store the object ID and have a separate
// thread pick it up, get the object, and close the object's window.
// This is, what we are doing below.
// Write ScriptID into tags
TagGroup tgs = GetPersistentTagGroup()
tgs.TagGroupSetTagAsLong( "DummyTag_CloseWindow_ID", self.ScriptObjectGetID() )
// Launch separate thread just to close... (0.1 sec delay for safety)
AddMainThreadSingleTask( self, "DeferredClose", 0.1 )
}
TagGroup CreateDLG(object self)
{
TagGroup DLGtg,DLGtgItems
DLGtg=DLGCreateDialog("my Dialog",DLGtgItems)
DLGtgItems.DLGAddElement(DLGCreatePushButton("Close","CloseButtonAction"))
return DLGtg
}
}
{
object dialog=Alloc(myDLG)
dialog.Init( dialog.CreateDLG() )
dialog.display("")
}
所以:
对于 GMS 3.2 及更高版本:使用self.close();
对于 GMS 3.0 和 3.1(带有错误):使用解决方法。
对于 GMS 2.x:使用self.close();
对于 GMS 1.x:使用self.GetFrameWindow().WindowClose(0);