Lua GameJolt API [Highscore tables / achievements]

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Guard13007
Party member
Posts: 132
Joined: Sat Oct 25, 2014 3:42 am
Location: Internet, USA
Contact:

Re: Lua GameJolt API [Highscore tables / achievements]

Post by Guard13007 »

This looks pretty cool and I'm glad to see that it's really being worked on. I can't wait to try it out. ^^
User avatar
Dreanh
Prole
Posts: 27
Joined: Fri Oct 10, 2014 2:36 am
Location: Norway

Re: Lua GameJolt API [Highscore tables / achievements]

Post by Dreanh »

Thanks for making this library, have been waiting for it since I uploaded my game to GameJolt. :awesome: Have implemented it in my game, but I'm having some issues when fetchScores(10) & authUser(name, token)
Image
This happens about 1 out of 10 tries when fetching or authenticating.

Also does anyone have the right pattern for matching username? I don't quite understand the pattern formating.

EDIT: It's on line 26 on the first error tried fixing it myself didn't work very well (if s == nil then return end), that line was commented on that error though.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Lua GameJolt API [Highscore tables / achievements]

Post by Positive07 »

This happens when the request altogether errors, I'm trying to fix this and submit a patch... check the internet connection and that you didnt place any weird character like spaces o tabs, those are not escaped so they error

EDIT: Try printing the values passed to fetch and auth and check what I pointed above, another help for debugging is printing req, you can change this:

Code: Select all

return string.find(req(...),"SUCCESS")
To this:

Code: Select all

local s = req(...) --This is the same function you could find inside the returned string.find
print(s)
return string.find(s,"SUCCESS") --String.find, the same values but instead of a new request, the value you got before
Check your own values, I wrote it from the back of my mind so its not like this but you get the idea
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
Dreanh
Prole
Posts: 27
Joined: Fri Oct 10, 2014 2:36 am
Location: Norway

Re: Lua GameJolt API [Highscore tables / achievements]

Post by Dreanh »

Today when I was going try debugging like you suggested, the error doesn't happen anymore. Haven't changed any code, so it's probably something with my connection. I've been printing username and token all along, so they should be right.

If it returns though it was something like this you meant?

Code: Select all

function GJ.authUser(name, token)
	GJ.username = name
	GJ.userToken = token
	
	local r = req("users/auth/?", "dump", true, true)
	print(r)
	local s = string.find(r, "SUCCESS") ~= nil
	GJ.isLoggedIn = s
	return s
end


Another thing though I tried GJ.pingSesion() every 30 sec as wiki suggested, it freezes the game for a second every time. Do I have to run another thread?(I know almost nothing about threads yet) And is it even necessary if I don't have trophies? Could I do GJ.openSession() before I GJ.fetchScores() or GJ.addScores()?



Also I've added this libraries functions into commands in the newly posted LOVEConsole, hope someone can find it useful.

Code: Select all

console.addCommand("GJinit", function(args)
	if args then
		if GJ.init(args[1], args[2]) then
			console.success("Initialised GameJolt API.")
		else
			console.error("Didn't initialise GameJolt API.")
		end
	else
		console.error("No arguments! - [gameid] [gamekey]")
	end
end, "Initialise GameJolt API - Arguments: [gameid] [gamekey]")

console.addCommand("GJauthUser", function(args)
	if args then
		if GJ.authUser(args[1], args[2]) then
			console.success(args[1] .. " is now connected to GameJolt.")
		else
			console.error("Didn't connect, try again.")
		end
	else
		console.error("No arguments! - [username] [token]")
	end
end, "Authenticate user - Arguments: [username] [token]")

console.addCommand("GJopenSession", function(args)
	if GJ.isLoggedIn then
		if GJ.openSession() then
			console.success("Opened session.")
		else
			console.error("Didn't open session")
		end
	else
		console.error("You are not logged in to GameJolt.")
	end
end, "Open Session")

console.addCommand("GJpingSession", function(args)
	if args then
		if args[1] == "active" then
			if GJ.pingSession(true) then
				console.success("Pinged as active.")
			else
				console.error("Didn't ping")
			end
		elseif args[1] == "idle" then
			if GJ.pingSession(false) then
				console.success("Pinged as active.")
			else
				console.error("Didn't ping")
			end
		else
			console.error("Wrong arguments! - [idle/active]")
		end
	else
		console.error("No arguments! [idle/active]")
	end
end, "Ping Session - Arguments: [idle/active]")

console.addCommand("GJcloseSession", function(args)
	if GJ.closeSession() then
		console.success("Closed session.")
	else
		console.error("Did not close session.")
	end
end, "Close Session")

console.addCommand("GJisLoggedIn", function(args)
	if GJ.isLoggedIn then
		if userInfo then
			console.print(userInfo.username .. " is logged in to GameJolt.")
		else
			console.print("You are logged in to GameJolt.")
		end
	else
		console.print("You are not logged in to GameJolt.")
	end
end, "Check if user is logged in to GameJolt")

console.addCommand("GJfetchUserBy", function(args)
	if args then
		if args[1] == "id" and tonumber(args[2]) then
			if GJ.isLoggedIn then
				local userInfo = GJ.fetchUserByID(args[2])
				console.print("Fetching user info...")
				console.print("ID: " .. userInfo.id)
				console.print("Type: " .. userInfo.type)
				console.print("Username: " .. userInfo.username)
				console.print("Avatar URL: " .. userInfo.avatar_url)
				console.print("Signed up: " .. userInfo.signed_up)
				console.print("Last logged in: " .. userInfo.last_logged_in)
				console.print("Status: " .. userInfo.status)
				if userInfo.type == "Developer" then
					console.print("Developer name: " .. userInfo.developer_name)
					console.print("Developer website: " .. userInfo.developer_website)
					console.print("Developer description: " .. userInfo.developer_describtion)
				end
			else
				console.error("You are not logged in to GameJolt!")
			end
		
		elseif args[1] == "name" then
			if GJ.isLoggedIn then
				userInfo = GJ.fetchUserByName(args[2])
				console.print("Fetching user info...")
				console.print("ID: " .. userInfo.id)
				console.print("Type: " .. userInfo.type)
				console.print("Username: " .. userInfo.username)
				console.print("Avatar URL: " .. userInfo.avatar_url)
				console.print("Signed up: " .. userInfo.signed_up)
				console.print("Last logged in: " .. userInfo.last_logged_in)
				console.print("Status: " .. userInfo.status)
				if userInfo.type == "Developer" then
					console.print("Developer name: " .. userInfo.developer_name)
					console.print("Developer website: " .. userInfo.developer_website)
					console.print("Developer description: " .. userInfo.developer_description)
				end
			else
				console.error("You are not logged in to GameJolt!")
			end
		else
			console.error("Wrong arguments! - [id/name] [actual id or name]")
		end
	else
		console.error("No arguments! - [id/name] [actual id or name]")
	end
end, "Fetch User Info - Arguments: [id/name] [actual id or name]")

console.addCommand("GJgiveTrophy", function(args)
	if args then
		if GJ.isLoggedIn then
			if tonumber(args[1]) then
				if GJ.giveTrophy(args[1]) then
					console.success("Gave trophy with ID: ." .. args[1])
				else
					console.error("Didn't give trophy")
				end
			else
				console.error("You did not enter a number!")
			end
		else
			console.error("You are not logged in to GameJolt!")
		end
	else
		console.error("Wrong argument! - [trophy id]")
	end
end, "Give trophy by ID - Arguments: [trophy id]")

console.addCommand("GJfetchTrophy", function(args)
	if args and tonumber(args[1]) then
		if GJ.isLoggedIn then
			if tonumber(args[1]) then
				console.print("Fetching trophy info...")
				trophyInfo = GJ.fetchTrophy(args[1])
				for i,v in ipairs(trophyInfo) do
					console.print("")
					console.print("ID: " .. v.id)
					console.print("Title: " .. v.title)
					console.print("Description: " .. v.description) 
					console.print("Difficulty: " .. v.difficulty) 
					console.print("Image URL: " .. v.image_url)
					console.print("Achieved: " .. v.achieved)
				end
			else
				console.error("You did not enter a number!")
			end
		else
			console.error("You are not logged in to GameJolt!")
		end
	else
		console.error("Wrong argument! - [trophy id]")
	end
end, "Fetch trophy by ID - Arguments: [trophy id]")

console.addCommand("GJfetchTrophiesByStatus", function(args)
	if args then
		if GJ.isLoggedIn  then
			if args[1] == "achieved" then
				console.print("Fetching trophies...")
				trophiesStatus = GJ.fetchTrophiesByStatus(true)
			elseif args[1] == "unachieved" then
				console.print("Fetching trophies...")
				trophiesStatus = GJ.fetchTrophiesByStatus(false)
			else
				console.error("Wrong argument! - [achieved/unachieved]")
			end
			for i,v in ipairs(trophiesStatus) do
				console.print("")
				console.print("ID: " .. v.id)
				console.print("Title: " .. v.title)
				console.print("Description: " .. v.description) 
				console.print("Difficulty: " .. v.difficulty) 
				console.print("Image URL: " .. v.image_url)
				console.print("Achieved: " .. v.achieved)
			end
		else
			console.error("You are not logged in to GameJolt!")
		end
	else
		console.error("No arguments! - [achieved/unachieved]")
	end
end, "Fetch trophies by status - Arguments: [achieved/unachieved]")

console.addCommand("GJfetchAllTrophies", function(args)
	if GJ.isLoggedIn  then
		console.print("Fetching trophies info...")
		trophies = GJ.fetchAllTrophies()
		for i,v in ipairs(trophies) do
			console.print("")
			console.print("ID: " .. v.id)
			console.print("Title: " .. v.title)
			console.print("Description: " .. v.description) 
			console.print("Difficulty: " .. v.difficulty) 
			console.print("Image URL: " .. v.image_url)
			console.print("Achieved: " .. v.achieved)
		end
	else
		console.error("You are not logged in to GameJolt!")
	end
end, "Fetch all trophies")

console.addCommand("GJaddScore", function(args)
	if args then
		if GJ.isLoggedIn then
			if GJ.addScore(args[1], args[2], args[3], args[4], args[5] ) then
				console.success("Score added.")
			else
				console.error("Score not added.")
			end
		else
			console.error("You are not logged in to GameJolt!")
		end
	else
		console.error("No arguments! - [score] [desc] [tableID] [guestName] [extraData]")
	end
end, "Add score - Arguments: [score] [desc] [tableID] [guestName] [extraData]")

console.addCommand("GJfetchScores", function(args)
	if args then
		if GJ.isLoggedIn then
			if args[2] and tonumber(args[1]) and tonumber(args[2]) then
				console.print("Fetching scores...")
				scores = GJ.fetchScores(args[1], args[2])
				console.print("")
			elseif not tonumber(args[2]) and args[2] then
				console.error("You did not enter a number! (Argument 2)")
			elseif not args[2] then
				console.print("Fetching scores...")
				scores = GJ.fetchScores(args[1])
				console.print("")
			end
			for i,v in ipairs(scores) do
				console.print(
					i .. ". " ..
					" Score: " .. v.score .. 
					" Sort: " .. v.sort .. 
					" ExtDat: " .. v.extra_data .. 
					" User: " .. v.user .. 
					" UserID: " .. v.user_id ..
					" Guest: " .. v.guest .. 
					" Stored: " .. v.stored
					)
			end
		elseif not tonumber(args[1]) then
			console.error("You did not enter a number!(Argument 1)")
		else
			console.error("You are not logged in to GameJolt!")
		end
	else
		console.error("No arguments! - [How many scores to fetch]")
	end
end, "Fetch scores - Arguments: [How many scores to fetch]")

console.addCommand("GJfetchTables", function(args)
	if GJ.isLoggedIn  then
		console.print("Fetching score tables...")
		tables = GJ.fetchTables()
		console.print("")
		for i,v in ipairs(tables) do
			console.print(
				"ID: " .. v.id .. 
				" Name: " .. v.name .. 
				" Description: " .. v.description .. 
				" Primary: " .. v.primary
				)
		end
	else
		console.error("You are not logged in to GameJolt!")
	end
end, "Fetch Score Tables")

console.addCommand("GJfetchData", function(args)
	if args then
		if GJ.isLoggedIn  then
			console.print("Fetching data...")
			data = GJ.fetchData(args[1], args[2])
			console.print("Key: " .. args[1] .. " Data: " .. data)
		else
			console.error("You are not logged in to GameJolt!")
		end
	else
		console.error("No arguments! - [key] [true/false]")
	end
end, "Fetch Data - Arguments: [key] [true/false]")

console.addCommand("GJsetData", function(args)
	if args then
		if GJ.isLoggedIn  then
			console.print("Storing data...")
			if GJ.setData(args[1], args[2], args[3]) then
				console.success("Data is stored.")
			else
				console.error("Data is not stored.")
			end
		else
			console.error("You are not logged in to GameJolt!")
		end
	else
		console.error("No arguments! - [key] [data] [true/false]")
	end
end, "Set Data - Arguments: [key] [data] [true/false]")

console.addCommand("GJupdateData", function(args)
	if args then
		if GJ.isLoggedIn  then
			console.print("Updating data...")
			if GJ.updateData(args[1], args[2], args[3], args[4]) then
				console.success("Data is updated.")
			else
				console.error("Data is not updated.")
			end
		else
			console.error("You are not logged in to GameJolt!")
		end
	else
		console.error("No arguments! - [key] [value] [operation] [true/false]")
	end
end, "Update Data - Arguments: [key] [value] [operation] [true/false]")

console.addCommand("GJremoveData", function(args)
	if args then
		if GJ.isLoggedIn  then
			console.print("Removing data...")
			if GJ.removeData(args[1], args[2]) then
				console.success("Data removed.")
			else
				console.error("Data was not removed.")
			end
		else
			console.error("You are not logged in to GameJolt!")
		end
	else
		console.error("No arguments! - [key] [true/false]")
	end
end, "Remove Data - Arguments: [key] [true/false]")

console.addCommand("GJfetchStorageKeys", function(args)
	if args then
		if GJ.isLoggedIn  then
			console.print("Fetching storage keys...")
			keys = GJ.fetchStorageKeys(args[1])
			console.print("")
			for _, v in ipairs(keys) do console.print(v) end
		else
			console.error("You are not logged in to GameJolt!")
		end
	else
		console.error("No arguments! - [true/false]")
	end
end, "Fetch storage keys - Arguments: [true/false]")
Haven't tested it much though.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Lua GameJolt API [Highscore tables / achievements]

Post by Positive07 »

Dreanh wrote:Today when I was going try debugging like you suggested, the error doesn't happen anymore. Haven't changed any code, so it's probably something with my connection. I've been printing username and token all along, so they should be right.
Well that is good, anyway, I want to fix this someday haha
Dreanh wrote:If it returns though it was something like this you meant?
Yeah exactly that!
Dreanh wrote:Another thing though I tried GJ.pingSesion() every 30 sec as wiki suggested, it freezes the game for a second every time. Do I have to run another thread?(I know almost nothing about threads yet) And is it even necessary if I don't have trophies? Could I do GJ.openSession() before I GJ.fetchScores() or GJ.addScores()?
Yeah, you need to make it asynchronous, but that is not in the scope of this lib, since the lib is not made for LÖVE but Lua in general, so I'm working on a rework of this lib which works asynchronously in LÖVE

PS: The session is just to show in the GameJolt page that the user is playing the game, you can avoid it entirely!
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
ManInBlackSweater
Prole
Posts: 17
Joined: Sat Aug 10, 2013 6:44 pm
Contact:

Re: Lua GameJolt API [Highscore tables / achievements]

Post by ManInBlackSweater »

Whoa, GameJolt.lua is growing up pretty fast! :awesome:
Take a look at what we've got in a month:

- Set up a wiki so you can start using GJ in your game real quick.
- Added basic Quick Play support (tested with LÖVE)
- Made things more "require friendly", so you can just use require "gamejolt"
- Updated md5.lua to latest version
- Added GJ.getCredentials, which makes it easier to get user credentials which are auto cached by library
- A lot of other little but cool tweaks

Thanks to amazing team. :nyu:
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Lua GameJolt API [Highscore tables / achievements]

Post by Positive07 »

ManInBlackSweater wrote: - Added basic Quick Play support (tested with LÖVE)
Currently it only works in Windows but the issue has been reported to the GameJolt team and we hope it will be fixed
ManInBlackSweater wrote: - Updated md5.lua to latest version
Yeah and, if I'm not wrong, that means something like 40000% faster hashing!!. A really big impact for this lib, since all the request need to be hashed (and that means MANY requests!)
ManInBlackSweater wrote: Thanks to amazing team. :nyu:
Glad to being part of this, an amazing library!
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: Lua GameJolt API [Highscore tables / achievements]

Post by josefnpat »

make gamesssss
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 38 guests