Dialogs unique identifiers (no longer maintained)
#61

Quote:
Originally Posted by ZeeX
After a bit of thinking I realized that the method which I posted above is not so good as I thought, so I wrote this one:

As you can see here I call special function called AddDialog for each my dialog only once
and it stores new dialog ID in some variable passed by reference (dialog1, dialog2 and dialog3 in my case), then I use those IDs for ShowPlayerDialog and OnDialogResponse. Now it's more like a work with menus...
I really think you should be promoting this method, not trying to list every dialog as that's simply not maintainable, I don't want to have to worry about what IDs are and aren't taken, that should be a detail abstracted away from scripters. I would suggest a slight modification, as posted below, but it's only a minor thing. The major problem is that people are just choosing random IDs, so if you have three IDs and want to add another one, the next number may already be taken and you have to find another one - plus I can see arguments starting about who got an ID first, and why does one person get that one when I wanted it?

pawn Code:
#include <a_samp>

new
    dialog1,
    dialog2,
    dialog3;

public OnFilterScriptInit()
{
    dialog1 = AddDialog();
    dialog2 = AddDialog();
    dialog3 = AddDialog();
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (PRESSED(KEY_CROUCH))
    {
        ShowPlayerDialog(playerid, dialog1, 0, "caption 1", "info 1", "button1 1", "button2 1");
    }
    if (PRESSED(KEY_JUMP))
    {
        ShowPlayerDialog(playerid, dialog2, 0, "caption 2", "info 2", "button1 2", "button2 2");
    }
    if (PRESSED(KEY_SPRINT))
    {
        ShowPlayerDialog(playerid, dialog3, 0, "caption 3", "info 3", "button1 3", "button2 3");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if (dialogid == dialog1)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Dialog 1 response");
    }
    else if (dialogid == dialog2)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Dialog 2 response");
    }
    else if (dialogid == dialog3)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Dialog 3 response");
    }
    else
    {
        return 0;
    }
    return 1;
}

stock AddDialog()
{
    new
        dialogs;
    dialogs = getproperty(0, "dialogs");
    setproperty(0, "dialogs", dialogs + 1);
    return dialogs;
}
The only real change is returning the new ID instead of getting it via pass by reference as it didn't make much sense. I also updated the examples with wiki code, but that's minor.
Reply
#62

Quote:
Originally Posted by Y_Leѕѕ
I really think you should be promoting this method, not trying to list every dialog as that's simply not maintainable, I don't want to have to worry about what IDs are and aren't taken, that should be a detail abstracted away from scripters.
I wasn't aware of this post or his second post and I'm not sure if you're speaking to me as you quoted Zeex but I will reply anyway dude. I agree with what you say about this method being promoted, it's by far the better method (now) and it kills off this thread so I will no longer have to maintain it. The released dialogs would need to be updated but that's a minor issue really, the most important thing is to make sure people use the new method as apose to the one I was promoting or it defeats the purpose of using it as they could still conflict but I don't think it's likely to happen as most are hundreds or thousands of ids apart and unless you have like one thousand etc in your script then the property id won't ever be that high of a number.

What about deleting the property in Exit(), is this an issue ?

Do they get destroyed (made zero) when the script exits or do they stick around in some global buffer or something that's shared between filters and gamemodes ?
Reply
#63

IDs are global to all scripts (via properties). They could be removed when a dialog is destroyed but it's not worth it really - that would require massively more code to find empty slots rather than just get the next known to be available ID.
Reply
#64

Quote:
Originally Posted by Y_Leѕѕ
IDs are global to all scripts (via properties). They could be removed when a dialog is destroyed but it's not worth it really - that would require massively more code to find empty slots rather than just get the next known to be available ID.
Cheers for the reply and info.
Reply
#65

2 - Simple Rules
http://forum.sa-mp.com/index.php?topic=125923.0
Reply
#66

Quote:
Originally Posted by allarw [u-rp.com
Cheers.

Edit:

Please take a look here -> http://forum.sa-mp.com/index.php?topic=127478.0
Reply
#67

Quote:
Originally Posted by Donny
Quote:
Originally Posted by ZeeX
pawn Code:
stock CreatePlayerDialog(playerid, style, caption[], info[], button1[], button2[])
{
    new
      dialogid;
    dialogid = getproperty(0, "dialogs");
    ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);
    setproperty(0, "dialogs", dialogid+1);
    return dialogid;
}
This function allows you create dialogs without worrying about their IDs as they are increased automatically, it is like when you create a textdraw you remember its ID to use it further
pawn Code:
new dialog = CreatePlayerDialog(playerid, 0, "caption", "info", "button1", "button2")

Nice function and method dude.

Edit:

List updated also.
Wow that just made my scripting lfe a hell lot easier
Reply
#68

I do for example:
new Dialog[10];
and I use in my dialog Dialog[0], Dialog[1], Dialog[2], Dialog[3], Dialog[4],..
Is that the same?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)