"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
louie999
Prole
Posts: 46
Joined: Fri Mar 06, 2015 9:01 am

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

Post by louie999 »

I have another set of questions, about lua-enet , how can I make players control their character with lua-enet?
like:
host created
player 1 joins
player 2 joins
...
Then each player can control 1 unit/character, like player 1 can control unit1, player 2 controls unit2 etc. will peer:connect_id() suffice for that? or is there a complicated approach I need to do to achieve that?

Is it possible to create a lobby or something similar where players can see all the created rooms/host then they can connect to it by simply pressing a "Connect" button ?

How can I update everything that's happening in the game to all the connected clients of a enet host? like if player 1 moved his unit or using a weapon/firing then the other players can see it too. Or if player 1 shoots then when the projectile hits a player then that player will see that he got hit. I hope someone can help me with these things as it's hard as hell for me :death:

Code: Select all

fun = true
school = true

function isItFun()
    if school then
       fun = false
    end
    if not fun then 
       me:explode()
    end
end
User avatar
nkorth
Prole
Posts: 15
Joined: Sun Sep 18, 2011 8:54 pm
Contact:

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

Post by nkorth »

louie999 wrote:I have another set of questions, about lua-enet , how can I make players control their character with lua-enet?
like:
host created
player 1 joins
player 2 joins
...
Then each player can control 1 unit/character, like player 1 can control unit1, player 2 controls unit2 etc. will peer:connect_id() suffice for that? or is there a complicated approach I need to do to achieve that?

Is it possible to create a lobby or something similar where players can see all the created rooms/host then they can connect to it by simply pressing a "Connect" button ?

How can I update everything that's happening in the game to all the connected clients of a enet host? like if player 1 moved his unit or using a weapon/firing then the other players can see it too. Or if player 1 shoots then when the projectile hits a player then that player will see that he got hit. I hope someone can help me with these things as it's hard as hell for me :death:
You'll need to use peer:send whenever each player does something to tell the server the new "state" of their character. (ie. their position, direction, whatever is changing) The server's job could then potentially be as simple as simply receiving these updates, then sending them along to all the other players. (an "echo server".) Of course, the server will probably end up being more complex than that, especially if you want to make a lobby, or do cheating prevention, or batch together updates to improve network speed.

Edit: also, make sure that you include some sort of player "id" in the peer:send messages, so the other game instances know what to do with them! You could make the server assign and send each player their "id" as soon as they connect, or better yet you could solely distinguish them on the server (because it can already tell peers apart), and make it add the player id as it forwards the update messages.
Grubby
Prole
Posts: 35
Joined: Sat Jun 01, 2013 2:46 am

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

Post by Grubby »

Develop games for what target resolution?

The title says it all. What resolution do most of you target? Do you shoot for widescreen 16:9/16:10 -> (1280x720 or 1920x1080) or do you go for 4:3 -> (1024x768 or 1280x1024) I'd assume by default, that most modern monitors cater to widescreen.

Just curious...
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post by zorg »

Grubby wrote:Develop games for what target resolution?

The title says it all. What resolution do most of you target? Do you shoot for widescreen 16:9/16:10 -> (1280x720 or 1920x1080) or do you go for 4:3 -> (1024x768 or 1280x1024) I'd assume by default, that most modern monitors cater to widescreen.

Just curious...
I'm fond of 4:3 and 5:4 (1280x1024 is the latter) currently, but if one has a different aspect ratio, then i believe games should adapt in any way possible (and fair, depending on the type of game), with letter/pillarboxing, or stretching (mostly useful when drawing to a canvas).
To tell the truth, i believe that this depends most on the game you want to make.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

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

Post by airstruck »

Given two vectors, how can I determine the shortest direction to rotate the first vector to project it onto the second vector (clockwise or counterclockwise)?

Right now I'm converting both vectors to angles and checking whether the difference between the angles is positive or negative. Is there a shortcut?
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

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

Post by davisdude »

You could try projecting one vector onto the other, then correct it's magnitude. I don't know if this will be any easier/faster, but you could try it. If magnitude doesn't matter it's even better.
Never mind, misread question :P
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Fantos
Prole
Posts: 11
Joined: Sat Aug 08, 2015 9:22 am

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

Post by Fantos »

Hi there guys, I'm new around here and I stuck on something, or more accuretly don't know what cause it and it gonna be good to know.
So I use STI, and simply I have a platform(polygon), and a box. The box fall on the platform, that good but when I move it sideway the box don't fall when reach end of the platform. What weird its happening only if the box touch the platform for around one second. After that the box have to touch another platform, or gravity don't affect it again. I overlook something about love.physics? I miss something?
Here the code:
http://pastebin.com/zQ8ePQMj
And here the love file:
Attachments
physics and other witchcraft.love
(10.56 KiB) Downloaded 81 times
User avatar
Jasoco
Inner party member
Posts: 3725
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 didn't want to create a thread for a simple question like this.

Why doesn't this code work?

Code: Select all

local shuffleRNG = love.math.newRandomGenerator(seed)
function shuffle(t)
	table.sort(t, function(a, b) return shuffleRNG:random() > 0.5 end)
end
If I use normal math.random() instead, it works fine. But if I use the love.math RNG, it errors with a "Invalid sort function" message.

I thought I could create a simple shuffle function, but I guess I'll use a more complex version from online that will probably work fine with the love.math RNG stuff.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin »

I didn't think using math.random() would work either.

I'd just use:

Code: Select all

local shuffleRNG = love.math.newRandomGenerator(seed)
function shuffle(t)
    for i = #t, 2, -1 do
        local j = shuffleRNG:random(1, i)
        t[i], t[j] = t[j], t[i]
    end
end
I don't think sorting with a random comparison function would work well in any case, since it depends so much on the order of comparison.

EDIT: quoting Wikipedia:
A variant of the above method that has seen some use in languages that support sorting with user-specified comparison functions is to shuffle a list by sorting it with a comparison function that returns random values. However, this is an extremely bad method: it is very likely to produce highly non-uniform distributions, which in addition depends heavily on the sorting algorithm used.

[...]

In principle this shuffling method can even result in program failures like endless loops or access violations, because the correctness of a sorting algorithm may depend on properties of the order relation (like transitivity) that a comparison producing random values will certainly not have. While this kind of behaviour should not occur with sorting routines that never perform a comparison whose outcome can be predicted with certainty (based on previous comparisons), there can be valid reasons for deliberately making such comparisons. For instance the fact that any element should compare equal to itself allows using them as sentinel value for efficiency reasons, and if this is the case, a random comparison function would break the sorting algorithm.
Last edited by Robin on Sat Aug 15, 2015 11:01 am, edited 1 time in total.
Help us help you: attach a .love.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post by zorg »

Jasoco wrote:I didn't want to create a thread for a simple question like this.

Why doesn't this code work?

Code: Select all

local shuffleRNG = love.math.newRandomGenerator(seed)
function shuffle(t)
	table.sort(t, function(a, b) return shuffleRNG:random() > 0.5 end)
end
If I use normal math.random() instead, it works fine. But if I use the love.math RNG, it errors with a "Invalid sort function" message.

I thought I could create a simple shuffle function, but I guess I'll use a more complex version from online that will probably work fine with the love.math RNG stuff.
I tried recreating it in the online lua sandbox, substituting math.random for love's prng that you use, and sometimes it worked, other times it didn't.
I'm guessing table.sort errors if the sorting function behaves unexpectedly or something.
Edit: behaving unexpectedly, like for values of 2 and 3, both being bigger and smaller than each other.
Try it out:

Code: Select all

local shuffleRNG = {}
math.randomseed(os.time())
shuffleRNG.random = function(self) return math.random() end
function shuffle(t)
   table.sort(t, function(a, b)
local r = shuffleRNG:random()
local d = r > 0.5
print(a,b,r,d)
return d end)
end
local tbl = {4,2,5,3}
shuffle(tbl)
for i,v in ipairs(tbl) do print(i,v) end
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Locked

Who is online

Users browsing this forum: No registered users and 73 guests