System Dialog System

Reaction score
341
Dialog System
TriggerHappy187​

Introduction :

This system allows you to make dialogs easier.

Requirements :
  • ABC ( Included in the map )

Changlog:

Version 1.1
  • Fixed TriggerAction leak.
  • Removed bj_ prefixes.
  • Struct variables are now private.

Version 1.0a
  • Fixed the destroy method
  • Tidied up the demo usage

Code :

JASS:
library Dialogs requires ABC

globals
    private constant integer BUTTON_AMOUNT   = 16
endglobals

struct Dialog
    
    private button array Button[BUTTON_AMOUNT]
    private integer ButtonCount
    private dialog Dialog
    private string name
    private string array ButtonName[BUTTON_AMOUNT]
    private trigger DIALOG
    private string clicked
    
    static method create takes string name returns Dialog
        local Dialog d       = Dialog.allocate()
        set d.Dialog         = DialogCreate()
        set d.name           = name
        set d.ButtonCount    = 0
        set d.DIALOG      = CreateTrigger()
        
        call SetDialogStructA(d.Dialog, d)
        
        call TriggerRegisterDialogEvent(d.DIALOG, d.Dialog)
        
        return d
    endmethod
    
    method Conditions takes nothing returns boolean
        return true
    endmethod
    
    method ShowAll takes nothing returns nothing
        local integer i = 0
        call DialogSetMessage(this.Dialog, this.name)
        loop
            exitwhen i > 11
            call DialogDisplay(Player(i), this.Dialog, true) 
            set i = i + 1
        endloop
    endmethod
    
    method ShowPlayer takes player p returns nothing
        call DialogDisplay(p, this.Dialog, true) 
    endmethod
    
    method createButton takes string ButtonName returns nothing
        set this.ButtonCount                  = this.ButtonCount + 1
        set this.Button[this.ButtonCount]     = DialogAddButton(this.Dialog, ButtonName, 0)
        set this.ButtonName[this.ButtonCount] = ButtonName
    endmethod
    
    method createAction takes code func returns nothing
        call TriggerAddCondition(this.DIALOG, Condition(func))
    endmethod

    method result takes nothing returns string
        local button b = GetClickedButton()
        local integer i = 0
        loop
            exitwhen i > BUTTON_AMOUNT
            if this.Button<i> == b then
                return this.ButtonName<i>
            endif
            set i = i + 1
        endloop
        return null
    endmethod
    
    method onDestroy takes nothing returns nothing
        call ClearDialogStructA(.Dialog)
        call DestroyTrigger(.DIALOG)
        call DialogDestroy(.Dialog)
    endmethod 
    
endstruct

    function ShowDialog takes Dialog d returns nothing
        call d.ShowAll()
    endfunction 
    
    function ShowDialogPlayer takes Dialog d, player p returns nothing
        call d.ShowPlayer(p)
    endfunction
    
    function AddButton takes Dialog d, string ButtonName returns nothing
        call d.createButton(ButtonName)
    endfunction
    
    function AddAction takes Dialog d, code func returns nothing
        call d.createAction(func)
    endfunction
    
    function ClickedButton takes Dialog d returns string
        return d.result()
    endfunction
    
    function GetDialog takes nothing returns integer
        return GetDialogStructA(GetClickedDialog())
    endfunction
    
    function ClearDialog takes Dialog d returns nothing
        call d.destroy()
    endfunction
    
endlibrary</i></i>


Demo Usage :

JASS:
scope test initializer InitTrig

globals
    Dialog test
endglobals

private function Actions takes nothing returns boolean // MUST HAVE RETURNS BOOLEAN
    local Dialog d = GetDialog() // This is needed!
    if ClickedButton(d) == &quot;Yes&quot; then // Checks if the button that was clicked was &quot;Yes&quot;
        call BJDebugMsg(&quot;Damn Straight!&quot;)
    elseif ClickedButton(d) == &quot;No&quot; then // Checks if the button that was clicked was &quot;No&quot;
        call BJDebugMsg(&quot;.....Shutup&quot;)
    endif
    call ClearDialog(d)
    return false // THIS MUST BE AT THE END OF THE FUNCTION
endfunction

private function CreateDialog takes nothing returns nothing
    set test = Dialog.create(&quot;Do you like Clan Mapz?&quot;) // Creates the Dialog + it&#039;s name
    call AddButton(test, &quot;Yes&quot;) // Creates a button call &quot;Yes&quot;
    call AddButton(test, &quot;No&quot;) // Creates a button call &quot;No&quot;
    call AddAction(test, function Actions) // The actions for the dialog
    call ShowDialog(test) // Shows the dialog to all players
endfunction

//===========================================================================
private function InitTrig takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEventSingle(t, 1.00)
    call TriggerAddAction(t, function CreateDialog)
endfunction

endscope
 

Attachments

  • Dialog System v1.0.w3x
    22.9 KB · Views: 201
  • Dialog System v1.0a.w3x
    20.3 KB · Views: 192
  • Dialog System v1.1.w3x
    23.2 KB · Views: 207

saw792

Is known to say things. That is all.
Reaction score
280
Why are you naming some of your globals/struct members bj_...?
 

Vestras

Retired
Reaction score
248
This already exists, made by cohadar.
Make this not use any attachment systems and it'll might be better. (Haven't tested it)
 

Flare

Stops copies me!
Reaction score
662
Dynamic triggers with triggeractions... if you are going to continue with dynamic triggers, at least use triggerconditions. Just convert the codefunc parameter to a boolexpr with Condition () or make the function take a boolexpr parameter, and use TriggerAddCondition instead of TriggerAddAction. And mention it in documentation that the function used for AddAction must return a boolean (IIRC, you should return false with dynamic triggers) i.e.
JASS:
function DialogClickedFunction takes nothing returns boolean
...
return false
endfunction

...
call AddAction (someDialog, Condition (function DialogClickedFunction))


JASS:
    function ClearDialog takes Dialog d returns nothing
        call d.onDestroy()
    endfunction

... you don't call the onDestroy method, that on it's own isn't very useful, since it doesn't recycle the struct index - call d.destroy () instead

JASS:
    function ShowDialog takes Dialog d returns nothing
        call d.ShowAll()
    endfunction 
    
    function ShowDialogPlayer takes Dialog d, player p returns nothing
        call d.ShowPlayer(p)
    endfunction
    
    function AddButton takes Dialog d, string ButtonName returns nothing
        call d.createButton(ButtonName)
    endfunction
    
    function AddAction takes Dialog d, code func returns nothing
        call d.createAction(func)
    endfunction
    
    function ClickedButton takes Dialog d returns string
        return d.result()
    endfunction
    
    function GetDialog takes nothing returns integer
        return GetDialogStructA(GetClickedDialog())
    endfunction
    
    function ClearDialog takes Dialog d returns nothing
        call d.onDestroy()
    endfunction

Lame BJ equivalents - those functions are pretty pointless. The struct methods are perfectly usable, so why do you need an extra function to call them?

And I can't find where you are using that Conditions function

Vestras said:
This already exists, made by cohadar.
And, your point being? There's numerous attachment systems in existence, but did it stop you from making one? If someone wants to make a system, they can, and there's no reason why anyone should try and stop them
 

Vestras

Retired
Reaction score
248
And, your point being? There's numerous attachment systems in existence, but did it stop you from making one? If someone wants to make a system, they can, and there's no reason why anyone should try and stop them

You wanted my system to be better than the others too - I just tell him what to do in order to make this better.
 

saw792

Is known to say things. That is all.
Reaction score
280
The difference between attachment systems and pretty much any other system is that creating a new attachment system DOES require it to be better than other systems. If it is not it provides no advantage and users will stick with more familiar/trustworthy/tried and tested systems.

This is not the case for systems such as this. Systems of this nature are not generally popular, and thus are less tested and develop less of a following. It is far more likely for a person to search for/ask for a dialog system than they will for CDS (an example name of a dialog system), in contrast to attachment systems where people will search for CSData over the generic category.

The point I'm trying to make is, this sort of system can get away with being 'worse' than others as long as it works, and does what is says it does. A new attachment system cannot get away with anything less than the best.
 

Flare

Stops copies me!
Reaction score
662
You wanted my system to be better than the others too
I did? I don't remember wanting that...

I just tell him what to do in order to make this better.
Well, system independence isn't really an option here - with timers, you have the option of looping through instances on, well, a timer :p With dialogs, you don't have the same freedom since the alternative is O(n) searches, and attachment > that

On further inspection...
JASS:
    method createAction takes code func returns nothing
        call TriggerAddAction(this.bj_DIALOG, func)
    endmethod

    method ShowPlayer takes player p returns nothing
        call DialogDisplay(p, this.Dialog, true) 
    endmethod

Lame BJ methods :p Both of those seem like something the end-user can/should do themselves (createAction is sort-of useful, but not very)
 
Reaction score
341
The "BJ" Functions are just there incase the user isnt used to , or gets confused by structs.

@Flare

Dynamic triggers with triggeractions... if you are going to continue with dynamic triggers, at least use triggerconditions. Just convert the codefunc parameter to a boolexpr with Condition () or make the function take a boolexpr parameter, and use TriggerAddCondition instead of TriggerAddAction. And mention it in documentation that the function used for AddAction must return a boolean (IIRC, you should return false with dynamic triggers) i.e.

lol , sorry not understanding what your getting at here.

EDIT :

1.0a released.
 

saw792

Is known to say things. That is all.
Reaction score
280
Triggeractions leak. Triggerconditions don't, and are executed faster, I believe.
 

saw792

Is known to say things. That is all.
Reaction score
280
He wants you to change your TriggerAddAction to TriggerAddCondition...
 
Reaction score
341
oh :p But doing that just makes it more confusing for the user, since conditions must return a boolean. Couldn't i just remove the leak and it would be better.
 

Flare

Stops copies me!
Reaction score
662
When you destroy a trigger, events and trigger conditions (AFAIK) are removed fine, but trigger actions aren't. There is an action to remove trigger actions, but it doesn't actually work o_O So, when the trigger is destroyed, the trigger actions are left floating around, doing nothing, being useless, and leaking

It may be more confusing, but it's safer


Alternatively, you could let the end-user handle the event registration and such i.e. the system handle dialog creation, adding buttons and so on, but end-user handles how they are 'applied' to triggers, so they could create the dialogs, then add the dialog events to pre-existing trigger(s) - that way, no dynamic triggers on their part, no leaking trigger actions. Only problem would be a little extra work, but in the interest of not breaking things, it seems like a reasonable deal :p
 

Flare

Stops copies me!
Reaction score
662
That depends on the map - what if you had a quest system that relied on dialogs for accepting/declining the quest? Perhaps an inventory system that used a quest (if, say, you have multiple inventory 'pages' and the dialog lets you pick what page to view).
Or just remove anything relating to trigger creation - as long as the end-user has access to the dialog variable, they can make the triggers themselves, so you rid yourself of any association with dynamic triggers :p

And 1 leak is still a leak - may not be much, but taking such an attitude towards leaks isn't a good idea, it all builds up

And
Submission Rules said:
Submissions with memory leaks will not be approved.

Anyway, it's very little work - add some bit of documentation, change TriggerAddAction to TriggerAddCondition, add Condition () around your existing action, is it really that hard?
 

BRUTAL

I'm working
Reaction score
118
i like this system, its pretty simple and easy to use
but whats this talk about 1 leak? will it affect gameplay alot if dialog is used like...medium ish; not alot, but then again not alittle : s
 

Azlier

Old World Ghost
Reaction score
461
Why is this any better than this?

EDIT: Oh. Vestras mentioned it. Nevermind then, I guess.
 

Azlier

Old World Ghost
Reaction score
461
Oh, this isn't new? Way to go, Brutal! You caused me to post in an old thread :mad: Meh, why don't I look at dates?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top