Legacy GM Pool game using Box2d

G

GabberMan

Guest
Hello Fel666,

I did this tutorial to see how the gameplay of pool work for an idea I have for a game but I can't make to change direction once it has begun to move the cue. I'd appreciate any help in this regard because I'm just starting and I'm a complete noob.

Thank you so much!
 

GMWolf

aka fel666
Hello Fel666,

I did this tutorial to see how the gameplay of pool work for an idea I have for a game but I can't make to change direction once it has begun to move the cue. I'd appreciate any help in this regard because I'm just starting and I'm a complete noob.

Thank you so much!
You should be able to remove the if(pulling) else part such that you can always orbit around the queue. You will also need to change a couple other areas.
 
R

RealsLife

Guest
You should be able to remove the if(pulling) else part such that you can always orbit around the queue. You will also need to change a couple other areas.
Woaaa the real GMWolf I'm subscribed 2 you for some time now :D! Btw I see you use a lot of local vars I never do that I always use instance variables is there a big difference in performance?
 

GMWolf

aka fel666
Woaaa the real GMWolf I'm subscribed 2 you for some time now :D! Btw I see you use a lot of local vars I never do that I always use instance variables is there a big difference in performance?
Its mostly a difference in memory.
The variables only stick around for that script / event.

Its also "more correct" as the variables do not belong to the instance, but to the script.
 

FrostyCat

Redemption Seeker
Btw I see you use a lot of local vars I never do that I always use instance variables is there a big difference in performance?
Treating the instance-scope-only habit as a performance problem is a myopic yet unfortunately common diagnosis. The lack of correctness is the main problem of the habit, and the bomb starts ticking once you start independent work.

The most common unwanted interaction is between looping variables inside and outside a script. Compare this correct implementation of capturing the values of 50 rolls of two dice:
Code:
for (var i = 0; i < 50; i++) {
  rolls[i] = d6(2);
}
Code:
///d6(n)
{
  var total = 0;
  for (var i = 0; i < argument0; i++) {
    total += irandom_range(1, 6);
  }
  return total;
}

With this incorrect implementation that just crashes flat-out, for no reason other than failing to use local variables:
Code:
for (i = 0; i < 50; i++) {
  rolls[i] = d6(2);
}
Code:
///d6(n)
{
  total = 0;
  for (i = 0; i < argument0; i++) {
    total += irandom_range(1, 6);
  }
  return total;
}

Another problem with the instance-scope-only habit is its interaction with recursion. Here's an easy example:

Correct:
Code:
///factorial(n)
// A correct recursive implementation of n!
{
  var n = argument0;
  if (n == 1) return 1;
  return factorial(n-1) * n;
}

Incorrect:
Code:
///factorial(n)
// An incorrect recursive implementation of n! that always returns 1
{
  n = argument0;
  if (n == 1) return 1;
  return factorial(n-1) * n;
}

And in case you think I'm creating these examples synthetically to prove a point, I'm telling you right now that they are based on actual posts I've responded to (loop counter conflict / recursion conflict). Real people have been bitten by the instance-scope-only bug, and it's not an old wives' tale. And thanks to this trend of incessant focus on performance, there is nearly zero awareness of it among rookies and intermediates.

So please stop looking at local variables in terms of performance, and stop treating it as optional or a matter of taste. It is a matter of keeping code correct and conflict-free, which often matters more than performance.
 
Last edited:

GMWolf

aka fel666
So please stop looking at local variables in terms of performance, and stop treating it as optional or a matter of taste. It is a matter of keeping code correct and conflict-free, which often matters more than performance.
This. Very much this.
People often dismiss "correctness". But it's really important. Performance is something you can worry about when you have good software engineering covered.
 
V

viking.potato

Guest
Do you plan to upload the final version on the marketplace?
 

Bentley

Member
@GMWolf Awesome tutorial. I was understanding everything until 22 minutes then...

Dot product!!! I've heard of a dot product in matrices, but not in vectors. I'll have to pause here and take some time to understand the "what" and the "why".
 

GMWolf

aka fel666
I'll have to pause here and take some time to understand the "what" and the "why".
A quick google search should helpp you understand.

But in essence, the dot product will find how much of a vector lies along the other vector. So if they are parallel, you get a high value, and when perpendicular, you get 0.
 
Top