Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-05-12 09:29:07, last edited by 1448 (2015-05-13 05:30:25)

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

[Question] Adding to list in case "say"

Can't seem to add items to a ListBox in case say.

if(playermessage.StartsWith("!admin") && AdminList.Items.Contains(username) && checkAddadmin)
{
    AdminList.Items.Add(playermessage.Substring(7));
    say(playermessage.Substring(7) + "is now an admin");
}

The above mentioned code does not work.

Offline

#2 2015-05-12 09:47:45, last edited by ewoke (2015-05-12 09:50:58)

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: [Question] Adding to list in case "say"

alkazam1448 wrote:

Can't seem to add items to a ListBox in case say.

if(playermessage == "!admin" && AdminList.Items.Contains(username) && checkAddadmin)
{
    AdminList.Items.Add(playermessage.Substring(7));
    say(playermessage.Substring(7) + "is now an admin");
}

nvm read something wrong

probably somethingwrong in the if statement


if you can read this....good for you

Offline

#3 2015-05-12 10:04:52

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: [Question] Adding to list in case "say"

You're probably receiving the error that you're trying to access a GUI element outside it's main thread.
To solve this you'll have to access the main thread (or something, I found this code snippet on stackoverflow a while ago).

MethodInvoker mi = delegate
            {
                // GUI element changes put here, in your case:
                AdminList.Items.Add(playermessage.Substring(7));
            };
            if (InvokeRequired)
            {
                BeginInvoke(mi);
            }
            else
            {
                mi.Invoke();
            }

Offline

#4 2015-05-12 10:58:22

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Question] Adding to list in case "say"

I'm putting everything in a try and catch, and I'm not catching any exceptions, so that might be it. I'll try. Thanks for the help.

Offline

#5 2015-05-12 11:08:29

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: [Question] Adding to list in case "say"

playermessage == "!admin" has to be playermessage.Contains("!admin")
or playermessage.StartsWith("!admin")

Offline

Wooted by:

#6 2015-05-13 05:16:47

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Question] Adding to list in case "say"

DarkDragon4900 wrote:

playermessage == "!admin" has to be playermessage.Contains("!admin")
or playermessage.StartsWith("!admin")

I wrote this code separately, so in my original code its StartsWith()

Offline

#7 2015-05-13 05:34:18

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Question] Adding to list in case "say"

den3107 wrote:

You're probably receiving the error that you're trying to access a GUI element outside it's main thread.
To solve this you'll have to access the main thread (or something, I found this code snippet on stackoverflow a while ago).

"code"

How exactly do you use a MethodInvoker class?

I understand how it works, like a function in JS, but what is:

den3107 wrote:
if (InvokeRequired)
{
    BeginInvoke(mi);
}
else
{
    mi.Invoke();
}

What does it do? When does it execute? What is an InvokeRequired?

Offline

#8 2015-05-13 08:22:09

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: [Question] Adding to list in case "say"

alkazam1448 wrote:
den3107 wrote:

You're probably receiving the error that you're trying to access a GUI element outside it's main thread.
To solve this you'll have to access the main thread (or something, I found this code snippet on stackoverflow a while ago).

"code"

How exactly do you use a MethodInvoker class?

I understand how it works, like a function in JS, but what is:

den3107 wrote:
if (InvokeRequired)
{
    BeginInvoke(mi);
}
else
{
    mi.Invoke();
}

What does it do? When does it execute? What is an InvokeRequired?

... you could just do at Form1() { }

CheckForIllegalCrossThreadCells = false;


Problem solved.
I used this in my bot and it worked.


http://i.imgur.com/bjvgH5L.png?1

Offline

#9 2015-05-13 09:16:36

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Question] Adding to list in case "say"

lel never though of that https://wiki.everybodyedits.com/images/9/9e/034_XP

Offline

14481431504996504238

Board footer

Powered by FluxBB

[ Started around 1732477955.38 - Generated in 0.049 seconds, 10 queries executed - Memory usage: 1.51 MiB (Peak: 1.67 MiB) ]