News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

Make level endings with a GUI

Started by argoon, July 02, 2014, 01:04:27 AM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

argoon

Original text by solarsplace (Arx - End of Sun) on  Doom3World with modifications by me (grammatical corrections mostly)


Here are the exact steps needed in order to:

- ingame, walk up to a GUI, set focus on the GUI, click a button and load another level.

This assumes that you know how to get a simple GUI made and into your map.

- for this you need two maps, replace yourmapname1.map and yourmapname2.map with the real names of your maps.

1 - Create a simple GUI to change the level. You can use the following code as a base if you want. This is a very simple GUI with a button on it. when clicked, the "onAction" code triggers a trigger_once entity placed in the yourmapname1.map called "trigger_once_1"



windowDef Desktop
{
   rect 0,0,640,480
     

    windowDef button1
   {
   rect 270,170,100,100
   visible 1

   backcolor 1,0,0,1
   forecolor 1,1,1,1
   textscale 0.1
   textalign 1
   text  "End Level"
   onAction{
         set "cmd" "activate trigger_once_1" ;
   }
   }
}




Save this as change_level.gui or whatever you like.

2 - Create a trigger_once entity in the map and make sure it is called "trigger_once_1" add a key val pair of "call" "next_map"

3 - In the same folder as yourmapname1.map create a text file called yourmapname1.script  and put the following code in it:



void next_map()
{
   sys.print ("\n Now ending this level\n"); //will NOT show this in the console if the next code is successful.
   sys.trigger ($target_endlevel_1);


4 - Create a target_endlevel entity in yourmapname1.map and call it "target_endlevel1" give it a key val pair of "nextMap" "yourmapname2.map" and thats it.


There may very well be a way to do it without using a script file, but using them makes life easier, it permits to write to the console and debug our code and see where it might be going wrong.   

Zombie

Nice tutorial!

But I would make one modification on there.

Instead of:

   onAction{
         set "cmd" "activate trigger_once_1" ;
   }


Use:

onAction {
set "cmd" "activate" ;

}


And then target the func_static where the GUI lives to the endlevel entity

This is much cleaner than specifying a hard fixed entity in the GUI to target.

It also allows reusability in the future.

I hope this helps!