Page 76 of 91

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

Posted: Mon Oct 17, 2016 2:45 pm
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:

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

Posted: Mon Oct 17, 2016 3:20 pm
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.

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

Posted: Mon Oct 17, 2016 4:02 pm
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.

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

Posted: Tue Oct 18, 2016 1:45 am
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

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

Posted: Tue Oct 18, 2016 1:53 am
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.

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

Posted: Tue Oct 18, 2016 1:58 am
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.

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

Posted: Tue Oct 18, 2016 8:20 pm
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)

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

Posted: Fri Oct 21, 2016 1:01 pm
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 :(

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

Posted: Fri Oct 21, 2016 1:06 pm
by raidho36
You can't access table until after it is created.

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

Posted: Fri Oct 21, 2016 2:28 pm
by milk
raidho36 wrote:You can't access table until after it is created.
So what would I do?