LUBE help! Class Commons [subclass?]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Maxwell
Prole
Posts: 11
Joined: Tue Dec 24, 2013 2:28 am

LUBE help! Class Commons [subclass?]

Post by Maxwell »

So I'm having a problem using LUBE. I read the article about how to use LUBE, and I understood that it uses a Class Commons library, and I picked the middleclass.lua library and along with middleclass-commons.lua

However it seems I am having a problem with syntax possibly?

-Code from the LUBE documentation guide-

Code: Select all

protocolClient = subclass(lube.Client)
protocolClient._implemented = true
-- define protocolClient
client = protocolClient()
The LUBE guide shows how to make an instance/object of the Client class. It doesn't explain much on what it's doing. I don't understand what the implemented variable is? Also not sure how protocolClient went from being a variable to a function seeing the last line showing protocolClient()
An explanation of the code might be helpful :)!

However when writing this using the Class Commons syntax since the LUBE guide stated it was just using a generic syntax. I don't understand why they're making a subclass inside the lube.Client class? I thought they're suppose to be making an object from it... Anyways my code that I made using the Class Commons guide after installing middleclass was this.

-line of code that gave me error-

Code: Select all

protocolClient = common.instance(lube.Client,'protocolClient')
LOVE responded me with
Can't use a generic client object directly, please provide an implementation
-all of the code-

Code: Select all

protocolClient = common.instance(lube.Client,'protocolClient')
protocolClient._implemented = true
-- define protocolClient
client = protocolClient()
Anyways I hope I gave you guys enough information to help me figure out what the problem is. Thank you :)!
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: LUBE help! Class Commons [subclass?]

Post by Davidobot »

You need to use either lube.udpClient or lube.tcpClient
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 1:38 am, edited 2 times in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE help! Class Commons [subclass?]

Post by bartbes »

Once again, because apparently nobody can read, that bit of code is a definition.
Furthermore, your problems stems from both trying to use the class commons api directly (almost never what you want), and confusing subclassing with instancing, indeed you can't make an instance of lube.Client, you can only subclass it. (And you don't want to subclass it either! Use one of the premade subclasses.)
Maxwell
Prole
Posts: 11
Joined: Tue Dec 24, 2013 2:28 am

Re: LUBE help! Class Commons [subclass?]

Post by Maxwell »

Thanks bartbes and everyone else!

I have another problem now though. I don't know how to set callback functions. In previous versions of LUBE people used server:setCallback function to se up their callback functions..

Code: Select all

server:setCallback(onReceive, onConnect, onDisconnect)
But now that function doesn't exist and on the LUBE 1.0 Documentation it says
You can set your callback functions in the callbacks table, there are 3 callbacks:
and I don't know what a callback table is :/ and Google didn't really help so I'm back here asking you :D thanks!
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: LUBE help! Class Commons [subclass?]

Post by Roland_Yonaba »

I never used LUBE, I am pretty new to networking, but this sounds very explicit, to me.
Here some code written from scratch. I inferred it from the source.

Code: Select all

local function onConnect(id)
  print('Client '..id..' is connected!')
end

local function onReceive(data, id)
  print('Received data from Client '..id..'!')
end

local function onDisconnect(id)
  print('Client '..id..' is connected!')
end

-- Assuming the server is defined
server.callbacks.connect = onConnect
server.callbacks.disconnect = onDisconnect
server.callbacks.recv = onReceive
Hope this helps.
Maxwell
Prole
Posts: 11
Joined: Tue Dec 24, 2013 2:28 am

Re: LUBE help! Class Commons [subclass?]

Post by Maxwell »

@Roland_Yonaba, it is not working :(
Here is my code.

Client

Code: Select all

-- CLIENT --
require ("middleclass")
require ("middleclass-commons")
require ("LUBE")

menu_screen = true
server_connect = false
response = ""

function love.load()

end

function love.update(dt)
	if server_connect == true then
	
	end
end

function love.draw()
	if menu_screen == true then
	love.graphics.print("Left Click to Join Server!", 100, 100)
	end
	love.graphics.print(response, 200, 200)
end

function love.mousepressed(x, y, button)
	if button == "l" then
	menu_screen = false
	server_connect = true
	Connect_To()
	end
end

function Connect_To()
client = lube.udpClient()
success, err = client:connect('I put my external IP here', 'I put my open port address here')
	if success == true then
	response = "CONNECTED"
	elseif success == false then
	response = "FAIL"
	else
	response = "IDK"
	end
end
Server

Code: Select all

--SERVER--
require ("middleclass")
require ("middleclass-commons")
require ("LUBE")

function love.load()
user_connect = ""
server = lube.udpServer()
server:listen('I put my open port here')
server.callbacks.connect = onConnect
end

function love.draw()
love.graphics.print(user_connect, 200, 200)
end

function love.update(dt)
server:update(0.01)
end

function onConnect(id)
user_connect = "USER CONNECTED"
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 218 guests