Server Code Errors

Hey guys I'm getting errors with this code. Can anyone help me?

I'll post the Error then current line

Error 1: C:\Users\Server\Desktop\Server\src\handlers\Talk.cpp|154|error: invalid use of 'this' in non-member function|

Line: this->player->character->Warp(Map, x, y, WARP_ANIMATION_ADMIN);

Error 2: C:\Users\Server\Desktop\Server\src\handlers\Talk.cpp|154|error: expected primary-expression before ',' token|

Line:this->player->character->Warp(Map, x, y, WARP_ANIMATION_ADMIN);

Error 3: C:\Users\Server\Desktop\Server\src\handlers\Talk.cpp|154|error: 'x' was not declared in this scope|

Line: this->player->character->Warp(Map, x, y, WARP_ANIMATION_ADMIN);

Error 4: C:\Users\Server\Desktop\Server\src\handlers\Talk.cpp|154|error: 'y' was not declared in this scope|

Line: this->player->character->Warp(Map, x, y, WARP_ANIMATION_ADMIN);

Now here is the whole code, well the section of it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	else if (character->player && message[0] == '#')
    {
        std::string command;
        std::vector<std::string> arguments = util::explode(' ', message);
        command = arguments.front().substr(1);
        arguments.erase(arguments.begin());

                if (command.length() == 4 && command.compare(0,4,"warp") == 0)
                {
                if (arguments[0] == "where you want it to warp you to")
                {
                this->player->character->Warp(Map, x, y, WARP_ANIMATION_ADMIN);
                }           
                }

        character->world->PlayerCommand(command, arguments, character);
    }
Last edited on
> invalid use of 'this' in non-member function|
A member function acts on an object.
In order to refer to the calling object inside the function, a hidden parameter this is passed.

You do not have a member function there, so there is no this pointer (¿what could be referring to?)


The other errors may be related.
Well here is the whole section/part of the code. Also, I'm not that good at coding just followed a tutorial on the forum, and I found out it was old and was for a different rev but apparently I can still use it. Anyhow here is the code;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
void Talk_Report(Character *character, PacketReader &reader)
{
	//if (character->muted_until > time(0)) return;
	//Checking mutes only on the public chat allows admins/players to use commands.

	std::string message = reader.GetEndString();
	limit_message(message, static_cast<int>(character->world->config["ChatLength"]));

	if (message.empty())
	{
		return;
	}

	if (character->admin && message[0] == '$')
	{
		std::string command;
		std::vector<std::string> arguments = util::explode(' ', message);
		command = arguments.front().substr(1);
		arguments.erase(arguments.begin());

		character->world->Command(command, arguments, character);
	}
    else if (character->player && message[0] == '#')
    {
        std::string command;
        std::vector<std::string> arguments = util::explode(' ', message);
        command = arguments.front().substr(1);
        arguments.erase(arguments.begin());

        if (command.length() == 4 && command.compare(0,4,"warp") == 0)
               {
               if (arguments[0] == "where you want it to warp you to")
               {
               this->player->character->Warp(Map, x, y, WARP_ANIMATION_ADMIN);
               }           
               }

        character->world->PlayerCommand(command, arguments, character);
    }
}
Last edited on
Topic archived. No new replies allowed.