"Questions that don't deserve their own thread" thread

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.
Locked
User avatar
evgiz
Citizen
Posts: 83
Joined: Mon Aug 29, 2016 11:05 pm
Contact:

Re: "Questions that don't deserve their own thread" thread

Post by evgiz »

pgimeno wrote: It's not a lot more efficient because these things are usually peanuts in comparison with the rest of the program, but it's one function call vs. three. Also, the square root used to take less cycles than trig functions; I haven't looked into the current status of things in more modern CPUs, though.
Thanks for the clarification! I'm probably going to continue using cos/sin because its what I'm used to and I often need the angle anyways. I'll keep this in mind tho if I'm ever doing something very performance sensitive! :nyu:
Computer science student and part time game dev! Currently working on Depths of Limbo! :cool:

Check out the game website DepthsOfLimbo.com! :ultrahappy:
And my personal website with all my projects evgiz.net! :megagrin:
User avatar
pgimeno
Party member
Posts: 3655
Joined: Sun Oct 18, 2015 2:58 pm

Re: "Questions that don't deserve their own thread" thread

Post by pgimeno »

Jack Dandy wrote:I have another question for now, related to synchronization.

Is the only thing that instantiates new threads the "love.thread.newThread " command?

I'm asking this because of the following problem:
I think there are cases in which a certain function A is called before another function B is finished (The call isn't made from within B, but by another thing), and that it messes up some variables.

Should I worry about synchronization if I'm not using love.threads?
If you're not using love.thread, what would you be using?

In love.thread, the threads don't share variables. You can't have functions that access the same variables. They can, however, share the same LÖVE data if you pass it among threads. From that standpoint, you don't need synchronization unless you are sharing LÖVE data and need it accessed orderly by each thread.

Not sure if that answers your question. I may have misunderstood it.
User avatar
Jack Dandy
Prole
Posts: 49
Joined: Mon Sep 08, 2014 4:26 pm

Re: "Questions that don't deserve their own thread" thread

Post by Jack Dandy »

I just managed to solve the problem - It was related to something a bit different.
I was using Hump.Timer a bit carelessly and it caused 2 functions to change variables when.. they shouldn't have.

However, your answer also supplies me with good data for the future.
I don't need to worry about synchronization as long as I don't explicitly create new threads and share data between them.
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: "Questions that don't deserve their own thread" thread

Post by Beelz »

What would be the best way to do a statistics save file? I have a few small casino games I'm trying to incorporate together and would like to have save-able stats between games, and plays. The file would be loaded at startup and saved after each round.

A: Serialize/de-serialize a table.

Code: Select all

stats = {
	money = 1000,
	played = 0,
	won = 0,
	lost = 0,

	blackjack = {
		played = 0,
		won = 0,
		lost = 0,
		profit = 0
	},

	holdem = {
		played = 0,
		won = 0,
		lost = 0,
		profit = 0
	}
	-- etc
}
or B: Like a configuration file line by line.

Code: Select all

MONEY 1000
PLAYED 0
WON 0
LOST 0
BJPLAYED 0
BJWON 0
BJLOST 0
BJPROFIT 0
HOLDPLAYED 0
HOLDWON 0
HOLDLOST 0
HOLDPROFIT 0
--etc

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: "Questions that don't deserve their own thread" thread

Post by Jasoco »

I use a table. That way I keep all savable variables in one table and for saving I can just use a library to dump it all into a string and write it to a file, and to load it's as easy as just replacing the same table by loading it executed. (Where you use the parenthesis after the load() function like variable = love.filesystem.load(file)().)

Then you can set up default preferences by just putting an identical preferences.lua file in your project. That way if you haven't changed anything, Löve will load the included built-in prefs file, and once you change something and save in the same place, from then on Löve will load that instead. And you can "reset to factory defaults" by simply deleting the file.

This works for anything from a preferences file to a save game file.
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: "Questions that don't deserve their own thread" thread

Post by Beelz »

Thank you so much for the quick reply, it will surely help! :ultrahappy: I've been throwing this on the back burner for a while now, as I wasn't sure what was best.

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
smunnelsnakzruule
Prole
Posts: 8
Joined: Thu Oct 13, 2016 12:36 pm

Re: "Questions that don't deserve their own thread" thread

Post by smunnelsnakzruule »

It appears the bug reports for canvas were out of date, the canvas seems to work fine. (width / static_size_virtual = scale_float)
User avatar
milk
Prole
Posts: 39
Joined: Sun Jul 17, 2016 7:20 pm

Re: "Questions that don't deserve their own thread" thread

Post by milk »

Just a quick question about nested tables, I have this:

Code: Select all

msgbox = {
	padding = 10,
	container = {
		x = 10,
		y = screen.H/2,
		w = screen.W-msgbox.padding*2,
		h = screen.H/5-msgbox.padding,
	},
	text = {
		x = msgbox.container.x,
		y = msgbox.container.y
	},
}
I would assume that for msgbox.container.w, where w= screen.W (screen width) - msgbox.padding*2 that it would simply be equal to screen.W-10, since msgbox.padding = 10, but I receive and error that says:
attempt to perform arithmetic on global 'padding' a nil value
Maybe I'm missing something here with nested tables, maybe one of you smarter people can give me a hand as to why I keep getting this?

I also tried moving padding outside the table and just named it padding, e.g. w = screen.W-padding, which worked fine, but then I would also get and error in msgbox.text, saying the same thing, so I'm certain it's a fault in my understanding of tables :(
Last edited by milk on Fri Oct 21, 2016 2:16 pm, edited 1 time in total.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: "Questions that don't deserve their own thread" thread

Post by raidho36 »

You can't access table until after it is created.
User avatar
milk
Prole
Posts: 39
Joined: Sun Jul 17, 2016 7:20 pm

Re: "Questions that don't deserve their own thread" thread

Post by milk »

raidho36 wrote:You can't access table until after it is created.
So what would I do?
Locked

Who is online

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