Code Monkey home page Code Monkey logo

action-network's People

Contributors

vocksel avatar

Stargazers

 avatar

Watchers

 avatar  avatar

action-network's Issues

Remove the need to use actions for networking

Requiring the use of Rodux style actions for networking is proving to be more cumbersome than it's worth.

Initially I was hoping this would be a convenient and intuitive way to communicate between server/client, but it's pretty clunky. It's also confusing having actions that could either be used for networking, and for the game's state.

So I propose the following API:

network:on(string eventName)
Returns an RBXScriptSignal that can then be connected to for when this event occurs.

network:on("foo"):connect(function(arg1, arg2, ...) end)

network:fire(string eventName, ...)
Server: Fires the event to all clients with the given arguments.
Client: Fires the event to the server with the given arguments.

network:fireTo(Player/table playerOrPlayers, string eventName, ...)
Server only. Fires the event to the given player or array of players.

network:fireExceptTo(Player/table playerOrPlayers, string eventName, ...)
Server only. Fires the event to all players except the one(s) specified.

Usage

Standard networking example, similar to what people are used to with RemoteEvents:

-- client
local network = Network.new(remote)
network:init()

-- listen on the client for an event
network:on("foo"):connect(function(bar)
    print(bar)
end)
-- server
local network = Network.new()
network:init()

-- fire the even,  will print "bar" on the client
network:fireTo(game.Players.Player1, "foo", "bar")

Another example, which allows you to do something very similar to the native action dispatching currently in place:

-- someAction
local action = {
  type = "action",
  foo = true
}
return action
-- client
local network = Network.new(remote)
network:init()

network:on(someAction.type):connect(function(someAction)
    print(action.foo) -- true
end)
-- server
local network = Network.new(remote)
network:init()

network:fire(someAction.type, action)

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.