Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendToPlayer error #31

Closed
comedinha opened this issue Aug 7, 2013 · 13 comments
Closed

sendToPlayer error #31

comedinha opened this issue Aug 7, 2013 · 13 comments
Labels
bug An issue describing unexpected behavior of code enhancement Increase or improvement in quality, value, or extent
Milestone

Comments

@comedinha
Copy link
Contributor

The function ModalWindow:sendToPlayer close the server (segmentation fault)

@marksamman
Copy link
Member

Please post the full script that crashes the server.

@comedinha
Copy link
Contributor Author

modaldialog = {
        title = "Offline Training",
        message = "Choose your room",
        buttons = {
                { id = 1, text = "Go" },
        },
        buttonEnter = 1,
        choices = {
                { id = 1, text = "Sword" },
                { id = 2, text = "Axe" },
                { id = 3, text = "Club" },
                { id = 4, text = "Distance" },
                { id = 5, text = "Magic Level" }
        },
        popup = false
}

function onStepIn(cid, item, position, fromPosition)
        local ModalWindow = ModalWindow(1001, title, message)
        if ModalWindow:getId() == 1001 then
                ModalWindow:doAddButton(buttons)
                ModalWindow:setDefaultEscapeButton(-1)
                ModalWindow:doAddChoice(choices)
                ModalWindow:setDefaultEnterButton(buttonEnter)
                ModalWindow:setPriority(popup)
        end
        ModalWindow:sendToPlayer(cid)
        registerCreatureEvent(cid, "Offline")
        return true
end

This is my offline train portal...

@marksamman
Copy link
Member

Change:
ModalWindow:sendToPlayer(cid)
To:
ModalWindow:sendToPlayer(Player(cid))

@comedinha
Copy link
Contributor Author

:O ty, more leaving only the cid is not easier?

@marksamman
Copy link
Member

I've fixed the crash, but I will leave this issue open to look into allowing cid instead of a player object.

@marksamman
Copy link
Member

You should be able to pass cid directly now.

@conde2
Copy link
Contributor

conde2 commented Aug 8, 2013

Just a question. This works without using:
modaldialog.title
modaldialog.message
...??

@marksamman
Copy link
Member

This works without your modaldialog table, yes. Title and message are just strings.

Example:
local modalWindow = ModalWindow(123, "My Modal Window", "This is a message")
modalWindow:doAddButton(1, "Go")
modalWindow:sendToPlayer(cid)

@comedinha
Copy link
Contributor Author

The function get title and get message no have use in script...

@marksamman
Copy link
Member

They return the title or message from the ModalWindow object. Just because "you" as a programmer know what you passed to the constructor doesn't make them redundant.

@conde2
Copy link
Contributor

conde2 commented Aug 8, 2013

I know that this are just parameters, but in the script posted by Bruno, the values comes from nowhere.
For me the script should be like that:

    local ModalWindow = ModalWindow(1001, modaldialog.title, modaldialog.message)
    if ModalWindow:getId() == 1001 then
            ModalWindow:doAddButton(modaldialog.buttons)
            ModalWindow:setDefaultEscapeButton(-1)
            ModalWindow:doAddChoice(modaldialog.choices)
            ModalWindow:setDefaultEnterButton(modaldialog.buttonEnter)
            ModalWindow:setPriority(modaldialog.popup)
    end

@dalkon
Copy link
Contributor

dalkon commented Aug 8, 2013

local modalWindow = ModalWindow(1001, modaldialog.title, modaldialog.message)
if modalWindow:getId() == 1001 then
    for _, v in ipairs(modaldialog.buttons) do
        modalWindow:doAddButton(v.id, v.text)
    end
    modalWindow:setDefaultEscapeButton(-1)
    for _, v in ipairs(modaldialog.choices) do
        modalWindow:doAddChoice(v.id, v.text)
    end
    modalWindow:setDefaultEnterButton(modaldialog.buttonEnter)
    modalWindow:setPriority(modaldialog.popup)
end
modalWindow:sendToPlayer(cid)

@comedinha
Copy link
Contributor Author

I fixed yesterday, now I got home and had answered it in school...
It is very easy to fix, a few minutes after the correction of the sendToPlayer I already had fixed...

Dalkon, this script was a little less work with mine, I'll create a function with it :3
I had not thought in "for"

But I have not seen the functionality the "get" functions...
No need get tittle, no need get message...
The get choice and get button have in "onModalWindow"
The only "get " function that needs to be used is getId()

Exemple my script:

function onModalWindow(cid, modalWindowId, buttonId, choiceId)
    if modalWindowId == 1001 then
        if buttonId == 1 or buttonId == 29 or buttonId == 0 then
            local pos = 0
            if (choiceId == 1) then
                pos = {x=98, y=45, z=15}
            elseif (choiceId == 2) then
                pos = {x=108, y=45, z=15}
            elseif (choiceId == 3) then
                pos = {x=117, y=45, z=15}
            elseif (choiceId == 4) then
                pos = {x=98, y=55, z=15}
            elseif (choiceId == 5) then
                pos = {x=117, y=55, z=15}
            end
            doTeleportThing(cid, pos)
        end
    end
    return true
end

PS. Buttton 29 and 0 is enter button...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue describing unexpected behavior of code enhancement Increase or improvement in quality, value, or extent
Projects
None yet
Development

No branches or pull requests

4 participants