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

style fix #30

Merged
merged 2 commits into from
Jun 19, 2022
Merged

style fix #30

merged 2 commits into from
Jun 19, 2022

Conversation

Mantou1233
Copy link
Contributor

w

@Visual1mpact
Copy link
Owner

You are subscribing to the function but not passing the object to the function as a parameter.

@Mantou1233
Copy link
Contributor Author

that also does work

@Visual1mpact
Copy link
Owner

Visual1mpact commented Jun 11, 2022

Before:
World.events.beforeChat.subscribe(msg => prefixcommand(msg));
After:
World.events.beforeChat.subscribe(prefixcommand);

msg would return undefined in

function prefixcommand(msg) {
    const player = msg.sender;

    commandHandler(player, msg);
}

@Mantou1233
Copy link
Contributor Author

how would it be undefined? didnt get it
passing the method itself is better than passing a method that calls a method with parms

@Mantou1233
Copy link
Contributor Author

function callback(caller, args){
    caller(args)
}
callback(console.log, 1) //1
callback((arg) => console.log(arg), 1) //1

they do the same thing

@Visual1mpact
Copy link
Owner

import { world } from "mojang-minecraft";
import { commandHandler } from "../../../commands/handler.js";

const World = world;

function prefixcommand(msg) {
    const player = msg.sender;

    commandHandler(player, msg);
}

const PrefixCommand = () => {
    World.events.beforeChat.subscribe(prefixcommand);
};

export { PrefixCommand };

You are subscribing to a function which expects a parameter to be defined. It's not being defined so when the parameter is later used in the function to define the player object it would essentially error.

msg.sender wouldn't return anything because msg wouldn't have anything to account for it.

It's the same scenario with the other files as well.

@Mantou1233
Copy link
Contributor Author

wdym by expects a parameter to be defined? params are passed to the prefixcommand function
World.events.beforeChat.subscribe(msg => prefixcommand(msg)); basicly pass a argument and repass that argument to prefixcommand

@Visual1mpact
Copy link
Owner

Yes, but you removed msg from the subscription. msg is the object which triggers the event. The object defines the properties for the message and the entity, specifically the player class, that sent the message. Without the object you cannot call its properties.

@Mantou1233
Copy link
Contributor Author

the object is passed to function prefixcommand(msg)'s msg, since it is just calling the method. ive done that a lot and it does always work. >_>

@Mantou1233
Copy link
Contributor Author

it does not expects a parameter to be defined, but pass that param and do the cb, so doing prefixcommand, msg is passed to prefixcommand

@Visual1mpact
Copy link
Owner

I just verified. It works. Though I can't say when this was allowed with Gametest because this wasn't the case for me in the past when I first began working on this project.

@Mantou1233
Copy link
Contributor Author

Mantou1233 commented Jun 11, 2022

it always works for me since i started doing gametest ¯\(ツ)/¯. anyways

@Visual1mpact
Copy link
Owner

I find that odd. Nonetheless, you still have a lot of other files that would need similar changes made to them for this patch to be complete.

@Mantou1233
Copy link
Contributor Author

ight

@Mantou1233
Copy link
Contributor Author

image
even you do that yourself ._.

@Mantou1233
Copy link
Contributor Author

ok i think its done

@Visual1mpact
Copy link
Owner

I'll check it out when I get a chance. Just now following up on your last reply.

@Visual1mpact
Copy link
Owner

image even you do that yourself ._.

That's because the function didn't expect a parameter.

function time() {
    // Code goes here
}

@Visual1mpact Visual1mpact merged commit 1c5d735 into Visual1mpact:main Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants