Putting the 'role' back in role-playing games since 2002.
Donate to Codex
Good Old Games
  • Welcome to rpgcodex.net, a site dedicated to discussing computer based role-playing games in a free and open fashion. We're less strict than other forums, but please refer to the rules.

    "This message is awaiting moderator approval": All new users must pass through our moderation queue before they will be able to post normally. Until your account has "passed" your posts will only be visible to yourself (and moderators) until they are approved. Give us a week to get around to approving / deleting / ignoring your mundane opinion on crap before hassling us about it. Once you have passed the moderation period (think of it as a test), you will be able to post normally, just like all the other retards.

Vapourware Trying to learn programming from ~0, realistic goals naturally help needed.

28.8bps Modem

Prophet
Joined
Jan 15, 2014
Messages
302
Location
The Internet, Circa 1993
Also, bitwise operators are used for sawing bits off larger numbers.

For (a contrived) example, lets say you had a counter that incremented every second:

Code:
int counter;

If you wanted an event to happen say, every 16 seconds you can say:

Code:
if ((counter & 0xf) == 0)
    do_event();

The bitwise and operator will give you the the bits of the larger number specified by the mask (0xf), in this case the bottom 4 bits. (0xf in hex = 15 in decimal = 1111 in binary.)
 

Raghar

Arcane
Vatnik
Joined
Jul 16, 2009
Messages
22,690
any reason why i should bitewise in python ?

Or should i ask why bitewise operations are a thing in higher language ?

My logic goes that if for example i will import data from files that are not in decimal then i would use bitewise to convert or to deal with them and export data to files which need to be in bytes.
I think Python is too abstract for going wild with bitshifts and AND/OR/XOR.

When you have a large strategy game and you need to know visibility of a hex for proper calculation, you can set one bit in "int" for each opponent, and that 1500x1500 hex map would still store itself in 2.14576721191 MB. Considering there are 10-15 of these arrays, savings are not negligible.

Also division is 40 cycle operation on CPU, bitshift is virtually free (with 1 OP) and pairs.

Then there are also things like a = b & 0xB0B0B0B0; .
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,867
thanks for info.

Hmm now i have different question.

How programmers deal with infinite loops ? I mean for example game loop.

If i set up some loop that will check for example if some variable is 1 (like a = 1 , print "you won game" break). This loop will go on and on and on and on possibly stressing CPU.

Are there any tricks to slow down loop process ? Like for instance do that script every 2 seconds instead of instantly ? Or even better every 15 seconds. So this small script willrun every 15 second practically not heaving any impact on game.
 

Raghar

Arcane
Vatnik
Joined
Jul 16, 2009
Messages
22,690
Thread t = new Thread(watchdog);
try{
t.sleep(15 minutes);
} catch(no way it would sleep whole 15 minutes exception e);
 

Declinator

Arbiter
Joined
Apr 1, 2013
Messages
542
thanks for info.

Hmm now i have different question.

How programmers deal with infinite loops ? I mean for example game loop.

If i set up some loop that will check for example if some variable is 1 (like a = 1 , print "you won game" break). This loop will go on and on and on and on possibly stressing CPU.

Are there any tricks to slow down loop process ? Like for instance do that script every 2 seconds instead of instantly ? Or even better every 15 seconds. So this small script willrun every 15 second practically not heaving any impact on game.

If I understand you correctly, the check itself need not be a loop. Inside your main loop (e.g. game loop) or inside a function your main loop calls you will have to check how much time has passed before initiating your check and after the check reset the timer.

For example:
Code:
while(true) {
  checkTimer += deltaTime;
  if(checkTimer >= 15) {
  if(a == 1) {
  print("you won game");
  }
  checkTimer = 0;
  }
  ...
}
 

Destroid

Arcane
Joined
May 9, 2007
Messages
16,628
Location
Australia
thanks for info.

Hmm now i have different question.

How programmers deal with infinite loops ? I mean for example game loop.

If i set up some loop that will check for example if some variable is 1 (like a = 1 , print "you won game" break). This loop will go on and on and on and on possibly stressing CPU.

Are there any tricks to slow down loop process ? Like for instance do that script every 2 seconds instead of instantly ? Or even better every 15 seconds. So this small script willrun every 15 second practically not heaving any impact on game.

You can use a function to tell your program to wait a certain amount of time (in python this is time.sleep(seconds)), a lot of game frameworks have this functionality already built in so you can specify a maximum frames per second.

https://docs.python.org/2/library/time.html
 

JMab

Augur
Joined
Nov 12, 2013
Messages
177
Location
Melbourne, Australia
To add to the posts above, you will have one "infinite" loop in your game that is normally called the MainLoop. This will keep executing until the user chooses to quit the game. Within the MainLoop in Windows, you check the message pump first, which gets filled by messages sent by Windows to the application. These might be window resize messages, window close messages, etc. You may not need to deal with this in Python, as it is probably dealt with at a lower level.

The execution of the rest of the loop is called "idle time", which is when there are no Windows messages to process. This is where your game executes, either continuously or during fixed time steps. The link SCO posted is the one usually referred to when debating what is better.

If you are continuously updating and rendering the game, you are maxing out the core that your game is executing on. This is where you see games or tech demos running at 100s of frames per second. A side effect of this this approach is that you have to scale all your update logic to the amount of time it took to update and render the last frame, to keep your entities moving at a consistent speed.

Alternatively you can "fix your timestep", which is typically done at 30 or 60 frames per second. This gives the advantage of not needing to scale your update logic. It is also necessary for your physics engine, as they all work better if updated at a consistent time step. Also, by running your game faster than than rate at which your monitor can refresh (typically 60Hz/60 frames per second), you risk seeing tearing on the screen, as the game has started rendering the next frame into the back buffer while the last is being presented to the screen by the monitor. This is avoided by turning on the vsync option in the config.

In your case, I wouldn't worry about maxing out your CPU in your main loop. I'd go as far to say that pretty much all game-playing CPUs currently in use are multi-core. So if you are running your game on a quad-core CPU, you'll only see 25% total utilisation for your game. The OS can keep merrily multitasking in the background on the other cores.

A "game won" check is something that can execute in negligible time. There would be just as much execution cost checking every frame as to whether it's time to check for whether the game is won. You'd be better off just checking for "game won" every frame, which gives the added advantage of the user getting the win message as soon as they win the game.
 

jagged-jimmy

Prophet
Joined
Jan 25, 2008
Messages
1,551
Location
Freeside
Codex 2012
Not sure you exactly need a game "loop". It depends on game and for simple stuff you can do it event driven. This might be simpler, as you just "react" on clicking and execute whatever. And stay idle most of the time.

This would be bad for tetris, but pretty fine for a turn-based game. Choose option, calculate, draw.... do nothing.
 

JMab

Augur
Joined
Nov 12, 2013
Messages
177
Location
Melbourne, Australia
You still need a main or game loop for event-driven programming as the job of the loop will be to listen for events and act upon them appropriately.

In a turn-based game with no idle animation you could try not continuously redrawing the scene, however you'd have to handle lots of events properly, like part of the window being invalidated because another window was dragged on top of it, or the window being minimised and restored, etc.

Apart from just being the way it is done (fixed or variable time steps), it does make some aspects easier...
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,867
Ok i feel like i shouldn't think to much about that now. Goal 2 should be event driven adventure game. After that i would need to think about proper gameplay
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,867
Ok let's do it. I have ton of free time today.
With every new thing i learn i have this feeling that my ideas quadruple. IT would be good feeling if it was just that.. point is that like for example yesterday when i was eating supper i completely flown off with ideas. I started to see patern in how to solve problems from game-play perspective and what is more important how to easily implement things without restructuring whole code or writing new games.
Just few days ago i was wondering how would I be able to create inventory without inputing manualy and deleting manualy every singe thing. I have always been closet game designer. I always had ideas about game systems, or what i should do. I just didn't have any programming skill beside simple if a > 2 then print "hello world". I have those sudden rushes of ideas with more or less complete answers how to implement them and i want instantly to do something about it but i know like in case of lists and dictionaries, answer which i know now, may be worst kind of way to implement.

And i don't mean grand things like make and 100h rpg. More like jamming system: instead of it being % wise make it bullet and % dependant. If i can make every bullet separate entity instead of being just a number like 10/23 (bullets/totalinmagazine) i can add interesting things like different types of ammo or their status like dirty or rusted which can have interesting effect on weapon you are using. Then when my mind is thinking about it i get another rush to my head. What if reload was perception dependent ? I mean in fallout therms if i had 1 perception i my character would have hard time to differentiate between rusted shitty ammo and actually good one which would have later effect on combat jamming system or even make weapon explode when you use something like grenade launcher. I didn't stop thinking about this and the ANOTHER rush of blood to head. HEY ! This means i could for example create different kinds of merchants ! This means for example that i can create merchant that will have better quality gear including bullets which would be much more expensive but you wouldn't need to check your bullets. HEY ! this means i can have shitty merchants too that will sell shitty quality gear including rusted bullets and stuff. HEY this also mean that i can have merchants that will be able to cheat ! Think about it ! merchant that sells kevlar armor for full price and under the hood there is some tin plate instead of kevlar plate

And since those things are systemic i wouldn't need to write anything more that few simple functions based on lists and dictionaries. Then i realize i am still fucking learning and it has only been like a week since i started. I know those things are doable for me now but maybe something i learn next day will change above to even shorter implementation so instead of writing above in few days i would be able to write it in hours.

Am i the only one with such problems ?
 
Last edited:

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,867
yeah it is one of my fears. Though good maxim is that the more things you create in system the less things you will need to individually adjust.

I got to OO. Seems interesting. Though mentioned inheritance is a bit confusing.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,867
heh yeah it seems confusing but i guess it is only as confusing as deep your class is.

Sure if you create some deep system of classes upon classes that would look like clusterfuck to figureout. But if i will for example create max 2step deep class then inheritance problems shouldn't be so confusing to figure out.

I thought up systems for my insert_game_name only in lists and dicts and that would imo work for many things like magazines, merchants and other stuff. Same with functions. Classes sure do sound interesting

That video about classes which @Burning Bridges posted here really now makes a sense and i see where trap is. Especially for classes which i didn't create myself.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,867
ok i gotta finish up OO then bit of I/O and then i will set my GOAL2. I think GOAL2 will be set in stone by this day end.
 

Raghar

Arcane
Vatnik
Joined
Jul 16, 2009
Messages
22,690
Example of OO:

class dog {
Leg leftForeleg
Leg rightForeleg
Leg leftHindleg
Leg rightHindleg
AttackingDevice at
}

class VAAN extends dog implements actionable{
public void action(ActionListener action){
action.addString("VAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN");
action.doAction();
}
}

For these who didn't get the joke.
In FFXII there was a character called Vaan, who was added as a "our audience would never accept non teenage character as a main character of a game". It was bit weird with him, as if developers were pissed at that as well, thus they named him Vaan. In case you don't understand Japanese, Vaan is japanese sound for "woof/wouaff/ouah".
 
Last edited:

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,867
================ GOAL 1 ACHIEVED ======================================

ibfpzDHKMjnQtw.jpg
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,867
GOAL 1 - SUMMARY

=============
=============
=============


Thoughts on this course. ==============================

It took me 4 days. If i had more time (read that as i would have full day for coding) i would probably do this in 15-16 hours. I could naturally speed things up to even half of that but then i wouldn't learn stuff which is far more important than just going without total understanding what is going on in code.

Things i should practice in Python for now ===================

- lists and dictionaries
- math connected to creating strings of numbers. mainly n+1 cases and math on those kind of things.
- keywords. Definitely i need to practice with them. Make some test case scenarios and so on.
- build in functions. At least i need to take a function and do few exercises with it.

Things i should look out for ============================

- more things on OO
- inheritance syntax in OO
- mentioned by posters cases with assigning x = y

The future ======================================

My Goal 2 is not yet set. Until yesterday i wanted to base it around making game with only lists and dictionaries, now when i saw OO i want to make also some OO stuff. Though i don't know if OO is right for me now as i need first to practice basic stuff instead of going into OO which was only briefly mentioned.


So now i will take few hours of free time and i will decide what to do next ( I was sitting on it from 6 a.m to 3 p.m. more or less without brake)
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
If you create your first classes you will get it wrong I am pretty sure.

First of all, use objects to describe data. This is trival and most people understand it very quickly, that's why the courses start with sutff like

class Animal
//some trivial shit about animals

class Dog: Animal
//some trivial shit about dogs

class Cat: Animal
//some trivial shit about cats

Etc. The problem is thinking these examples (Dog: Animal, Cat: Animal) teach you a lot about OO, and to stop there.

You can learn a lot more if you inherit real classes, and understand what it entails and what you be achieved with it.
Lets say your first goal is to create 2 (or more) custom Forms that already have some buttons buttons and features, but also a common look and feel.
I think this would be a good task to understand what you can really do with inheritance, and also extremely useful for someone making a game.

//"Form" is a synonym .. whatever your target language provides as a "window"

class BasicCustomForm: Form

class CustomForm1: BasicCustomForm

class CustomForm2: BasicCustomForm

You could put basic stuff in "BasicCustomForm" which is for your own custom look and feel, and functionality.

a simple example

Code:
class BasicCustomForm

var Border
var Space
var BackColor
var ForeColor
var Font

and a method Format() that adjusts all Controls to your Style

Code:
public Format()
{
var x=Border
foreach Control c in this.Controls
{
  c.Top = x
  c.BackColor = BackColor
  c.ForeColor = ForeColor
  c.Font = Font
  x=x+Space
}
}
Code:
class CustomForm1: BasicCustomForm
CustomForm1()
{
  //add some controls
  Format();
}
and the same for
Code:
class CustomForm2: BasicCustomForm
CustomForm2()
{
  //add some controls
  Format();
}
Hope you get the idea, I would recommend you examples like this and understand what you can really do with Objects.
Certainly not just model Cats and Dogs, this could already be done with ancient concepts like structs.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,867
What i have in mind with OO is more like fill for my procedural generation idea.

I can create basic template for let's say animal (think enemy) and this animal will have:

mass
attack
color

Then i can write simple loop script operating on list of random 1to10 numbers and crate 10 different animals based of function in that loop.
Then class will return me important things like if animal is big or small or heavy which then i can calculate in combat math.

Though i think for now i should practice with lists and dictionaries instead.
I currently think about what to put in GOAL2. I think i should focus on above and do simply practical game systems for my insertfuturegame project. Like magazine, backpack, basic monster and combat math. weapon generator based on materials and stuff like that. As goal3 i should connect dots and put it as a simple game. For now in python naturally.

Also i learned something about I/O but this was mainly basic .txt import export. Are thare any libaries for python that handle stuff like XML ? Naturally i could use notepad stuff but then i would need to write script that would find what is what in pure text. Importing via cells like a(1-20) would be much easier and faster as datastructure.

edit:
on a sidenote i wonder how I/O works in Dwarf Fortress as game raws are simple TXT files.
 
Last edited:

Ninjerk

Arcane
Joined
Jul 10, 2013
Messages
14,323
My Java class basically throws a bunch of shit at you with what feels like, "We'll explain this later/you'll understand once you use it more" style approach to OO.
 

As an Amazon Associate, rpgcodex.net earns from qualifying purchases.
Back
Top Bottom