Dialog which will preform different action on Yes,No (any buttons) per call as simple as possible
Usage examples;
Do you want to sell 'some' item?
Do you want to kill this player?
Are you sure you want to leave to group?
All in simple one function call + definition of ActionID - what should happen
note: this method is limited to displaying 1 dialog per player at given time to keep it simple and light
note2: this method is not inline with code. Action selection and execution is handled from separate trigger
Before reading
Any kind of visual modification (text style, labels sizes etc) is up to you. I won't cover it in this tutorial.
Creation process is in code tags. Each - possibly hard - line is explained in // comments
function - function with specified return type.
action - function with no return type.
[size] - indicates array of 'size' size.
<type> - indicates variable of 'type' type.
record - a structure defining group of variables stored under single object.
Player group(Player) - is function inserted in Player Group place found in 'Player Group -> Convert Player to Player Group'
Step 1 - Creating dialog
1.1:
Create record type named "YNDialog" - (right click in list of your triggers etc; New -> New Record)
In record's variables create - (select your new record type and create variables in right part)
CODE
YNDialogVariablesMaindialog=NoDialog<Dialog>Messagelabel=NoDialogItem<DialogItem>Yesbutton=NoDialogItem<DialogItem>Nobutton=NoDialogItem<DialogItem>ActionID=""<String[15]>// this will hold currently displayed YNDialog's ActionID for given player
1.3:
Create Global variable of your struct <YNDialog> named YNDialogVar" (whatever)
Global variables are those in left window part, not inside any triggers etc
Create action named "YNDialog Show" - this is what you will call everytime you need to pop Yes/No dialog (remember: one at time, otherwise last window will simply be overwritten)
CODE
YNDialogShowOptions:ActionReturnType:(None)ParametersPlayer=0<Integer>Message=NoText<Text>ActionID=""<String>LocalVariablesActions// Simple check to preform automatic initialization (optional)General-If(Conditions)thendo(Actions)elsedo(Actions)IfYNDialogVar.Maindialog==NoDialogThenYNDialogVarInitialize()Else// Dialog - Set Dialog Item TextDialog-SetYNDialogVar.MessagelabeltexttoMessagefor(Playergroup(Player))Variable-SetYNDialogVar.ActionID[Player]=ActionID// Dialog - Show/Hide DialogDialog-ShowYNDialogVar.Maindialogfor(Playergroup(Player))
Create trigger named "YNDialog Trigger" - this is where you will define what will happen on given ActionID
CODE
YNDialogTriggerEventsDialog-AnyDialogItemisusedbyPlayerAnyPlayerwitheventtypeClickedLocalVariables// Yes, No are Boolean variables if you wonder, you can see this at the end of variable declaration in <> tagsYes=((Useddialogitem)==YNDialogVar.Yesbutton)<Boolean>// Yes = ?// - Double click 'initial value'// - Scroll thru list untill you find 'Comparison'// - Value 1: Used Dialog Item ( found at bottom of dialog category )// - ==// - Value 2: YNDialogVar.Yes button ( found in variables section )No=((Useddialogitem)==YNDialogVar.Nobutton)<Boolean>// Same as above, just use 'No Button'Actiontoexecute=""<String>ConditionsYes!=No// ?// - if both are 'false' - means button pressed is not one of our buttons - it will fail and skip the rest of trigger// - same with both 'true' which is impossible// - if only one of those will be 'true' means other one will be 'false' and trigget will runActionsDialog-HideYNDialogVar.Maindialogfor(Playergroup((Triggeringplayer)))Variable-SetActiontoexecute=YNDialogVar.ActionID[(Triggeringplayer)]// You define every ActionID's outcomes here inside switchGeneral-Switch(Actions)dependingonActiontoexecuteCasesGeneral-If("Some ActionID")Actions// You can also use switch here if you have more buttonsGeneral-If(Conditions)thendo(Actions)elsedo(Actions)IfYes==TrueThen// do something on YESElse// do something on NODefault// In case you mistype somethingDebug-Display(Text((Combine("Missing definition for '",Actiontoexecute,"' ActionID"))))asdebugoutputusingType1,andDodisplayitinthegamewindow
ExampletriggerEventsTimer-Elapsedtimeis1.0GameTimesecondsLocalVariablesConditionsActions// Our target player in this case is player 1// Message is "It works?"// ActionID will be "test"YNDialogShow(1,"It works?","test")
General-Switch(Actions)dependingonActiontoexecuteCases//...General-If("test")ActionsGeneral-If(Conditions)thendo(Actions)elsedo(Actions)IfYes==TrueThenUI-Display"Correct."for(Allplayers)toSubtitleareaElseUI-Display"Wrong, it works!"for(Allplayers)toSubtitlearea
Universal Yes/No Dialog
Description
note: this method is limited to displaying 1 dialog per player at given time to keep it simple and light
note2: this method is not inline with code. Action selection and execution is handled from separate trigger
Before reading
//
commentsStep 1 - Creating dialog
1.1:
Create record type named "YNDialog" - (right click in list of your triggers etc; New -> New Record)
1.2: Screenshot
In record's variables create - (select your new record type and create variables in right part)
CODE
1.3:
Create Global variable of your struct <YNDialog> named YNDialogVar" (whatever) Global variables are those in left window part, not inside any triggers etc
Step 2 - Creating functions
2.1: Screenshot
Create action named YNDialogVar Initialize" - it must be run only once - prior to any attempt of displaying
CODE
2.2: Screenshot
Create action named "YNDialog Show" - this is what you will call everytime you need to pop Yes/No dialog (remember: one at time, otherwise last window will simply be overwritten)
CODE
2.3: Screenshot
Create trigger named "YNDialog Trigger" - this is where you will define what will happen on given ActionID
CODE
Step 3 - Example usage
3.1: Screenshot
Create trigger named "Example trigger"
CODE
3.2: Screenshot
Create new case for our "test" ActionID
In our "YNDialog Trigger":
CODE
3.3:
Done. Now just run the map and see if it works.
End
You can see attached map for more examples.