Giter Site home page Giter Site logo

rbxts-knit's People

Contributors

osyrisrblx avatar rwilliaise avatar spectrius avatar water261 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rbxts-knit's Issues

Infinite yield possible on 'ReplicatedStorage.rbxts_include.node_modules.knit.Knit:WaitForChild("Services")'

Whenever trying to import knit I get that error

Server:

import { KnitServer as Knit, Signal, RemoteProperty, RemoteSignal } from "@rbxts/knit";
import { Players } from "@rbxts/services";

declare global {
	interface KnitServices {
		CurrencyService: typeof CurrencyService;
	}
}

const CurrencyService = Knit.CreateService({
	Name: "CurrencyService",

	// Server-exposed signals/fields:
	MoneyPerPlayer: new Map<Player, number>(),
	MoneyChanged: new Signal<(player: Player, money: number) => void>(),

	Client: {
		// Client exposed signals:
		MoneyChanged: new RemoteSignal<(money: number) => void>(),
		GiveMeMoney: new RemoteSignal<() => void>(),

		// Client exposed GetMoney method:
		GetMoney(player: Player) {
			return this.Server.GetMoney(player);
		},
	},

	// Add Money:
	AddMoney(player: Player, amount: number) {
		let money = this.GetMoney(player);
		money += amount;
		this.MoneyPerPlayer.set(player, money);
		if (amount !== 0) {
			this.MoneyChanged.Fire(player, money);
			this.Client.MoneyChanged.Fire(player, money);
		}
	},

	SetMoney(player: Player, amount: number) {
		this.MoneyPerPlayer.set(player, amount);
		this.MoneyChanged.Fire(player, amount);
		this.Client.MoneyChanged.Fire(player, amount);
	},

	// Get Money:
	GetMoney(player: Player) {
		const money = this.MoneyPerPlayer.get(player);
		return money ?? 0;
	},

	// Initialize
	KnitInit() {
		print("CurrencyService KnitInit");
		const rng = new Random();

		this.Client.GiveMeMoney.Connect((player) => {
			const money = rng.NextInteger(0, 10);
			this.AddMoney(player, money);
			print(`Gave ${player.Name} ${money} money`);
		});

		Players.PlayerRemoving.Connect((player) => this.MoneyPerPlayer.delete(player));
	},
});

export = CurrencyService;

Client:

import { KnitClient as Knit } from "@rbxts/knit";

const MoneyService = Knit.GetService("CurrencyService");

function MoneyChanged(money: number) {
	print("My money:", money);
}

// Get money and listen for changes:
const initialMoney = MoneyService.GetMoney();
MoneyChanged(initialMoney);
MoneyService.MoneyChanged.Connect(MoneyChanged);

// Ask server to give money randomly:
MoneyService.GiveMeMoney.Fire();

// Advanced example, using promises to get money:
MoneyService.GetMoneyPromise().then((money) => {
	print("Got money:", money);
});

Component.d.ts missing parameters

The Component.d.ts file appears to be missing the dt parameter for all the corresponding functions (RenderUpdate, HeartbeatUpdate, SteppedUpdate)

HeartbeatUpdate?(): void; -> HeartbeatUpdate?(dt?: number): void;
SteppedUpdate?(): void; -> SteppedUpdate?(dt?: number): void;
RenderUpdate?(): void; -> RenderUpdate?(dt?: number): void;

The changes above should hopefully mitigate the issue if I'm not mistaken, while keeping it optional to have said parameter.

Using classes with a service on controller breaks since version 0.7

We're currently blocked from upgrading @rbxts/knit past version 0.6 because our "class method" no longer works. There are no errors and Knit reports that everything has started properly, but nothing runs. I have tried to diff the version and have found nothing which could cause this.

Our service and controller definitions look like this:

export const ExampleController = Knit.CreateController(
    new (class ExampleController extends KnitController {
        public Name = "ExampleController";

        public KnitStart() {}
    })(),
);

We do this because it is much easier to work in a class rather than an object (which is used by default).

I have gone into Knit's source and as far as I can tell, by the time that Knit.Start() runs, all services and controllers no longer have their methods or properties. Maybe there was a change introduced that removes the class metatable?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.