Thirsty Panther Posted January 13, 2015 Share Posted January 13, 2015 How do I end a Leadwerks program using a script. I would to like to end the program when the quit button is pressed but can't work out how to do this. Also should I release all entities and sounds before closing or doesn't it matter. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
nick.ace Posted January 13, 2015 Share Posted January 13, 2015 The App.lua script shows how you can do this: if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end So, if the App:Loop() method returns false, then the program will close. In your scenario, when you click a button just return false in the App:Loop() method if that button is pressed and the app will close. The second question can be complicated. I just looked it up on StackOverflow since I wasn't too sure about some of the things: http://stackoverflow.com/questions/9033931/memory-leak-c So, the OS releases memory for closed processes that aren't released. IDK if it's properly deallocated in the engine, but you don't really need to worry about this. For your purposes, it doesn't matter. 2 Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted January 13, 2015 Author Share Posted January 13, 2015 Thanks for the quick reply Nick. I looked at the way app.Lua closed and thought that would be the answer but my scripting skill is beyond it. How do I pass false to the App.Lua? I also thought I could just close the window when the button is pressed but I couldn't get window closed to work for me. Cheers for the help. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 13, 2015 Share Posted January 13, 2015 Ironically someone asked me the same question yesterday evening. Here is my suggestion on how you can do this: 1. In app.lua before the App.Start function, add the following variable: App.quitGame = false 2. in the main loop change the following line if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end with this: if self.window:Closed() or App.quitGame or self.window:KeyDown(Key.Escape) then return false end I simply added a check on whether the quiGame variable is true. Because if it is, then the App.Loop should be stopped. 3. Now, in your object script do the following: App.quitGame = true 1 Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted January 13, 2015 Author Share Posted January 13, 2015 Speaking of Irony, I'm trying to do this for your FlowGUI example map. Great product BTW? Thanks I think I can follow that. Thanks Aggror and Nick. 1 Quote Link to comment Share on other sites More sharing options...
Imchasinyou Posted January 13, 2015 Share Posted January 13, 2015 Speaking of Irony, I'm trying to do this for your FlowGUI example map. Great product BTW? Thanks I think I can follow that. Thanks Aggror and Nick. Im still stuck at loading my game from FlowGUI. . . . . lol, I can get a map to load but the main screen is still there. Although I cant get my head around writing scripts, I do try. Prolly why my head hurts all the time now. . . Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 13, 2015 Share Posted January 13, 2015 @imchasinyou: Have you removed the GUI items? I described this in an example in the PM I send you on 29 december. @Thirsty panter: Since so many people have questions about ending the game, I will propably do a quick video tutorial about it. 1 Quote Link to comment Share on other sites More sharing options...
Imchasinyou Posted January 13, 2015 Share Posted January 13, 2015 I have attempted this and as you know, given that you have helped me in the past, I'm not very good at learning scripting. I havnt gotten it figured out just yet. Where it makes perfect sense to you guys, some of us aren't "geared" this way. It's not that we don't try. It's fine if you don't want to help any one actually make sense with your system, it don't hurt me any. where one leaves off, another would be willing to accept my money! Quote Asus sabertooth 990FX, AMD FX 9590 , Windows 7 Home Premium 64 Bit, 4 HDD's Western Digital Caviar Black set in Raid 0, 16 GB Crucial Ballistix Elite, Asus Radeon R9 270 X 4GB, Corsair CM750M, Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 13, 2015 Share Posted January 13, 2015 It's fine if you don't want to help any one actually make sense with your system, it don't hurt me any. where one leaves off, another would be willing to accept my money! I have never said that I wouldn't help people with FlowGUI. When people have questions regarding the use of FlowGUI, they can send me a private message. Many have done so already and I am glad to help them out. Making entire gameplay scripts is an entire question. But again if you have a question regarding FlowGUI, you send me a pm about it. I would be happy to happy to have a look at it. If you have a script that doesn't work or when when you have trouble with FlowGUI, this is something I will assist in. Personally I find this not only my responsibility, it also lets gives me direct feedback in to what users want or what they expect. Let us not hijack this topic any further on this. Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted January 13, 2015 Author Share Posted January 13, 2015 @Thirsty panter: Since so many people have questions about ending the game, I will propably do a quick video tutorial about it. Sounds like a good idea. I'm also interested in loading my first level from FlowGUI. I haven't got this stage yet ( time poor ). I'm in the process of designing my intro screen. I've imported a new font, got some animated characters. Now I just need to add some music and load the first level. Many thanks again. Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted January 14, 2015 Author Share Posted January 14, 2015 Ironically someone asked me the same question yesterday evening. Here is my suggestion on how you can do this: 1. In app.lua before the App.Start function, add the following variable: App.quitGame = false 2. in the main loop change the following line if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end with this: if self.window:Closed() or App.quitGame or self.window:KeyDown(Key.Escape) then return false end I simply added a check on whether the quiGame variable is true. Because if it is, then the App.Loop should be stopped. 3. Now, in your object script do the following: App.quitGame = true Thanks Aggror. Got a chance to add this to my project and It works. Why do you use app.quitgame? why not just quitgame? Again many thanks. Quote Link to comment Share on other sites More sharing options...
beo6 Posted January 14, 2015 Share Posted January 14, 2015 probably so you can even set App.quitGame from any other entity script. But shouldn't quitGame = true also be global as long as you don't write local before it? Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted January 14, 2015 Author Share Posted January 14, 2015 So does the app part make the variable global? Quote Link to comment Share on other sites More sharing options...
Yue Posted September 25, 2021 Share Posted September 25, 2021 On 1/14/2015 at 2:44 PM, Thirsty Panther said: So does the app part make the variable global? Destroy Window. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.