Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 648 649 [650] 651 652 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887977 times)

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9735 on: June 12, 2016, 08:02:47 pm »

Good use with the prints for debugging, you get a much better idea of the order that bits of code are being called.

Here's what I like to do: have the debug print at the start of a function print out it's name and parameters. Include the class name as well for the most detail. e.g. for your dice constructor, instead of "hello", try printing:

System.out.println("Dice.Dice("+x+")");

Debug printing of the name of functions and what values they are getting can really save time when you know some bit of code is screwing up, but you're not sure where the problem is. I've had countless times that I've debugged some "faulty" bit of code over and over, only to do a debug and realize that another bit of code was sending it the wrong values. The first thing you should always double-check is what values a function is receiving.

Is that a feature in eclipse? I think i've seen it but never got around to actually using it. I'll definetly take a look at it tommorow after class.

Logged

Emma

  • Bay Watcher
  • Romace plots aren't actually that bad
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9736 on: June 12, 2016, 08:12:03 pm »

Focus on getting a quad to move back and forth and getting the jump mechanics working nice, gradually introduce more environmental complexity, then check how this actually interacts with your jump mechanics. Getting jumping feeling right in a sidescroller can be more involved than you think.
You might as well go straight to using sprites instead of quads actually, since there's no real difference in the programming but there's less stuff you have to get rid of later on. Reelya is right, though, getting a jump that both feels nice and works mechanically can be pretty difficult. A little tip, if you have a problem go straight to the documentation/Unity answers. The documentation can be found both online and as an HTML file that you can find where Unity was installed.
Logged

feelotraveller

  • Bay Watcher
  • (y-sqrt{|x|})^2+x^2=1
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9737 on: June 13, 2016, 01:47:50 am »

Thanks for the comments. 

After using Geany a fair bit more (pulseaudio I will put you down) over the last day or so (and discovering the split window plugin, duh) I'm a bit more happy with it.

Sublime and Atom both interest me but not being free, for the first, and newness for the second hold me back. 

I might revisit when and if the benefits of an IDE beckon.  Am I wrong to wait?
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9738 on: June 13, 2016, 02:00:50 am »

Hey! I'm thinking about making a basic 2D platforming game (basically just a re-skinned clone of the first level of Super Mario). I'm not really sure where to begin though. I already installed Unity, so that shouldn't be a problem, but otherwise, any advice?

If you want a sharp-edged pixel look, you're going to have to set the Filter Mode to "point" on all of your sprites. You can do this by navigating to the sprite in the Assets window and clicking on it, which will bring up the import settings.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Emma

  • Bay Watcher
  • Romace plots aren't actually that bad
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9739 on: June 13, 2016, 03:16:28 am »

Thanks for the comments. 

After using Geany a fair bit more (pulseaudio I will put you down) over the last day or so (and discovering the split window plugin, duh) I'm a bit more happy with it.

Sublime and Atom both interest me but not being free, for the first, and newness for the second hold me back. 

I might revisit when and if the benefits of an IDE beckon.  Am I wrong to wait?
While Sublime says it costs money I've been using the free version for a year or two and it hasn't locked me out. I should really buy a full copy  :-[, if only to support its devs.
Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9740 on: June 13, 2016, 06:29:33 am »

Thanks for the comments. 

After using Geany a fair bit more (pulseaudio I will put you down) over the last day or so (and discovering the split window plugin, duh) I'm a bit more happy with it.

Sublime and Atom both interest me but not being free, for the first, and newness for the second hold me back. 

I might revisit when and if the benefits of an IDE beckon.  Am I wrong to wait?
While Sublime says it costs money I've been using the free version for a year or two and it hasn't locked me out. I should really buy a full copy  :-[, if only to support its devs.
It's nagware. You'll keep getting an annoying popup telling you to buy.
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9741 on: June 13, 2016, 02:28:04 pm »

Have you tried emacs? :V
« Last Edit: June 13, 2016, 02:32:02 pm by Shadowlord »
Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9742 on: June 13, 2016, 04:50:32 pm »

So I'm trying to work out a general algorithm for what I'm referring to "calculations per second", the principle for simulators (or most games in general, I suppose) running in real-time where every second things need to get checked or updated. Biggest example of this that comes to my mind is DF.

Every second the game runs through a total amount of calculations, which is represented by FPS. So if FPS is 100, then 100 calculations are done a second. Obviously computers can perform a lot more calculations a second if the calculations are simple enough. But the code is set up so that it only does so many calculations a second.

Not really sure how to implement something like real-time calculations for a game that runs in real-time. Using C++. I'd think I would use <ctime>, although I'm not terribly familiar with all of the ctime functions. Tips?
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9743 on: June 13, 2016, 04:58:08 pm »

What would that get you that FPS doesn't provide, and what is a calculation?
Logged

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9744 on: June 13, 2016, 05:03:10 pm »

Spoiler (click to show/hide)

Hey guys, I have some trouble getting my program to roll multiple dice. I've tried doing a loop on main to contiunisly call a function to no avail. Then I thought "Why not ask a certain part of another class to roll for me when called.".

In this program when you ask to have a 100 sided dice for say, it'll transfer an int of 100 to the class and make an object. Then return said object.

I then attempt to get that object which I call 'First' and then ask First to access his special class that lets him roll a certain number of times. For some reason the first number inputted is consumed and the second number lost. Code is above.

Am I forgettig some rule for synthax here or is their something fundaentally wront with what i'm doing? I always thought it was Blueprint nameofobject = new Blueprint(arguments if needed);

then using

nameofobject.certainAbility(arguments if needed);

So yeah let me know if anyone has any ideas on what's going on and point me to the road to fix it. After this i'm basically done and i can get started on GUI. Then maybe put in an appstore to make billions (sarcastic joke).

But ya i'm thinking about putting it in an appstore to help shore up my resume.


Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9745 on: June 13, 2016, 05:09:42 pm »

Misread the code. Not touching it. Too burnt out on my own job to care.
« Last Edit: June 13, 2016, 05:42:08 pm by Mephisto »
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9746 on: June 13, 2016, 05:21:56 pm »

@Mephisto:No he does not.nevermind

Also, 3man75, good grief, you NEVER need to import Object.

I want to help with this, but I'd end up completely rewriting your code and not really helping.

Also, you really, really, really need to learn more about how to write readable variable names...AND STOP MAKING MULTIPLE SCANNERS POINTED AT SYSTEM.IN FOR LIKE THE TENTH OR SO TIME AAAUGH.  Sorry.  I shouldn't shout.  But you only need the one Scanner, let's call it input, and then you can call input.nextInt() multiple times.

...Also, screaming about THIS METHOD IS BEING CALLED BY MAIN! is...Not a guaranteed truth, in addition to being really weird documentation-wise, because the line of code you wrote ISN'T being called in main, it's being called in your method.  One's code should not depend on being called by certain other code unless it's a private method, which I will not talk about because that's outside your current scope.

...Sod it, I'm going to write an unconnected example in the hopes that it actually gets through.

Code: [Select]
import java.util.Scanner;
public class Demo{
Scanner scan = new Scanner(System.in); //And notice how there is ONE Scanner, not two or three.
public static void main(String[] args){
//I'll avoid complicating things and just write it to go through each method once, though simply wrapping this with a while loop and implementing some sort of menu shouldn't be hard.
System.out.println("Input the initial value for instancevariable");
DemoObject whatdoesitdo = new DemoObject(scan.nextInt()); //Much less code to write than creating a new variable to store a value you only use once.

//Now, to demonstrate proper object-based I/O.

System.out.println("Called singleUseThing and got "+whatdoesitdo.singleUseThing()); //This is what a return statement is for.  It hands data back to the method that called things.
System.out.println("How many times would you like to call multiUseThing?");
int[] output; //Have to declare this outside of the loop so it doesn't vanish after the first iteration.
for(int count = 0, int max = scan.nextInt() /*Reusing a Scanner, see?  Also, you can do this comma thing here.*/, output = whatdoesitdo.multiUseThing(max); count<max; count++){
System.out.println("Result "+(count+1)+" of multiUseThing was "+output[count]);
}
}
}

public class DemoObject{
int instancevariable;
Random RNGesus = new Random();
DemoObject(int setup_value){
instancevariable=setup_value;
}

public void setInstanceVariable(int to_set){
instancevariable = to_set;
}

public int singleUseThing(){
return RNGesus.nextInt()*instancevariable;
}

public int[] multiUseThing(int num_times){
int[] temp_storage = new int[num_times];
for(int count = 0; count<num_times; count++){
temp_storage[count] = RNGesus.nextInt()*instancevariable;
}
return temp_storage; //Handing the array back for whatever.  If you only wanted to print odd-numbered results, you could do that without mucking up the object for uses that need all the results printed.
}

I apologize for the tabs, but it was much faster than spaces, especially because I typed this on my phone
« Last Edit: June 13, 2016, 06:10:47 pm by TheBiggerFish »
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9747 on: June 13, 2016, 08:23:56 pm »

So I'm trying to work out a general algorithm for what I'm referring to "calculations per second", the principle for simulators (or most games in general, I suppose) running in real-time where every second things need to get checked or updated. Biggest example of this that comes to my mind is DF.

Every second the game runs through a total amount of calculations, which is represented by FPS. So if FPS is 100, then 100 calculations are done a second. Obviously computers can perform a lot more calculations a second if the calculations are simple enough. But the code is set up so that it only does so many calculations a second.

Not really sure how to implement something like real-time calculations for a game that runs in real-time. Using C++. I'd think I would use <ctime>, although I'm not terribly familiar with all of the ctime functions. Tips?

Here's a nice article on the different types of synchronization:
http://gafferongames.com/game-physics/fix-your-timestep/

Skimming over that, basically the solution is this:

Code: [Select]
double t = 0.0;
const double dt = 0.01;

double currentTime = hires_time_in_seconds();
double accumulator = 0.0;

while ( !quit )
{
    double newTime = hires_time_in_seconds();
    double frameTime = newTime - currentTime;
    currentTime = newTime;

    accumulator += frameTime;

    while ( accumulator >= dt )
    {
        updatePhysics();
        accumulator -= dt;
    }

    render( state );
}

But you probably want to cap the number of Physics Updates per Video Frame as well, to avoid a "death-spiral" (video can't keep up with required physics updates, so it ends up doing more physics updates per frame, which slows down the video, ad infinitum).

BTW use the <chrono> library for c++, as it is more accurate than the old <ctime>, which is only accurate to milliseconds.
« Last Edit: June 13, 2016, 09:10:12 pm by Reelya »
Logged

feelotraveller

  • Bay Watcher
  • (y-sqrt{|x|})^2+x^2=1
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9748 on: June 13, 2016, 08:44:58 pm »

Have you tried emacs? :V

My impression - bloated, slow, cumbersome.

I'm happy if it works for you and thanks for the suggestion.

edit: On Sublime, free beer is good, free speech is better. 
« Last Edit: June 13, 2016, 08:47:56 pm by feelotraveller »
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9749 on: June 13, 2016, 08:50:19 pm »

What would that get you that FPS doesn't provide, and what is a calculation?
Used DF as an example of the concept. What I was asking about doesn't involve DF at all. I was considering trying to write some kind of basic artificial life simulator that runs in real time. "Calculations" is referring to any sort of updating to members of classes, like a creatures' current status in a simulation. Say a basic plant creature that creates a set amount of energy per tick and after a certain amount of time builds up enough energy reserves and splits into two plant creatures. Or any kind of physics simulator (though that's an example way behind my abilities currently)

Rather than have the game run by turns like a simple roguelike, so that the timespan is measured in turns and the game isn't running/updating data without someone there to pass the turn, I wanted it to run in "real time" with the time-span measured in seconds, the game running and updating constantly without pause unless specified to pause by the user.

-snip-
Will look into this some more. The psuedocode you provided looks somewhat similar in principle to the incredibly basic example I hacked together on my own, except my program probably isn't handling time updates "properly" or accurately at all.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.
Pages: 1 ... 648 649 [650] 651 652 ... 796