Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Jargon that confuses new developers! Post your question or explanation here!

Author
Message
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 21st Aug 2011 01:30
What's a UTD? What's the difference between a string and an integer? What's a function? What's a subroutine? What does RGB mean?

We've all been there, searching google and scratching our heads when a more experienced developer starts speaking a different language.

So if there's an abbreviation, or word you don't know the meaning of. Ask here, I'm sure I or someone else will answer your question quickly.
Nickydude
Retired Moderator
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Look outside...
Posted: 21st Aug 2011 02:47
Also I would like to include any questions and answers in the AppGameKit Guide I'm putting together (if that's OK Daniel). If you don't want your Q / A in the guide please say so in your post.

I reject your reality and substitute my own...
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 21st Aug 2011 03:24
I would like to pose a question. It is simply why use a constant? I have seen that a lot of people use them, and I always ask myself why? For instance.

Why is there any need for the constant, when the single line will suffice? If I am setting gravity to 9.7, as long as I don't alter it in the code, it will remain 9.7 forever. I really don't understand any advantage to it.

So my question is what possible advantage can using constant give you? I am intrigued.

http://s6.bitefight.org/c.php?uid=103081
XanthorXIII
AGK Gold Backer
12
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 21st Aug 2011 04:10
To me constants are a good way to prevent you from accidentally changing a value that you did not mean to change. You will usually get a compiler warning if you try to change it's value.
The other reason let's say is if you were calculating taxes. You wouldn't hard code the rate of tax in your calculations. If the rate changed you would have to go back through your entire code to find the value to change. If you were to put that into a constant, you would only have to change one line.
There are also some C/C++ Reasons why you need to use a constant.
For example for protection against changing a value in a function that doesn't need to be changed. You can pass a value to a function and inside that declaration it is treated as a constant. You will do that mostly with character arrays.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 21st Aug 2011 04:42
I see your point DVader and here are my thoughts. A lot of us are used to programming by ourselves or maybe with a few friends but not on a large scale such as 100 developers. When programs get massive and there are multiple teams handling the development then inorder to prevent unwanted changes to a variable you would make it a constant.

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 21st Aug 2011 04:49 Edited at: 21st Aug 2011 04:58
XanthorXIII has pretty much nailed it.

Some extra cases for #constants and the reason I usually use them is for things like this:

#constant true 1
#constant false 0

this allows me to write If statements like this.

if getfileexists("data.dat") = true then deletefile("data.dat")

the alternative would naturally be

if getfileexists("data.dat") = 1 then deletefile("data.dat")

but many developers find it easier to read "true" then 1, usually because they are used to multiple languages such as C++ or Visual Basic. Now if you want to use this method, you sure as heck don't want true and false changing on you. It would break your program instantly!

I also use it to code in colours:

#constant black 0, 0, 0
setprintcolor(black)


and of course more complicated colours are easier to name, then remember the code too.

#constant crimson 220 20 60
#constant gold 205 215 0
#constant olive 128 128 0

etc etc

Another way I tend to use constants is for scancodes, I've not used these in AppGameKit but I use these in DarkBASIC Professional all the time

#constant a 30
#constant b 48
#constant c 46
#constant d 32

etc etc

this allows me to refer to the key specifically, without having to remember that keys scancodes.

When working on larger projects, I have a subroutine for DBPro saved, that I just include in any program, and all the basics are there, common colour names, scancodes, true, false, especially when I'm working on media-less code examples.

The colour codes are a very good reason for constants, if you were to do this with varibles, you'd have to setup a data type.

Type colours
r as byte
b as byte
g as byte
Endtype

gold as colours
gold.r = 205
gold.g = 215
gold.b = 0

setprintcolor(gold.r, gold.g, gold.b)


Constants don't have to worry about the type of data being held, they don't care if it's a float, a string or an integer. It just stored the colour code I normally type directly into setprintcolor and that's the end of it.

#constant gold 205 215 0
setprintcolor(gold)


easy, huh?
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 21st Aug 2011 05:11 Edited at: 21st Aug 2011 05:31
The readability point is a fair one. It could help others when reading your code. Also possibly for hacking reasons it may help as you say. I don't really think about that as I would consider it high praise for someone to bother hacking anything I have done.
The tax calculation I cannot see as an advantage however. I would want the tax rate to be definable in the interface, so it wouldn't be a constant at all. It wouldn't be a very versatile program to have to edit the code to change a VAT rate. Just a variable that can change as needed, either from user input or an update.
I welcome any other examples. I am a little old fashioned with my coding style, and tend to use subroutines rather than functions, so there are quite possibly a lot of ways they may be useful in that way. When I first started using DB I was used to plain a=a+1. The inc command seemed fairly superfluous, but as I used it more I got used to it. Now with AppGameKit I feel as if I have gone back to the stone age having to use the old formula, although it works exactly the same way

Edit- another post inbetween lol. The true and false argument is again based on readability, so fair enough, although I automatically treat 1 and 0 as on or off or true and false anyway. But as the sole coder I would know not to change the relevant variables anyway.
For colours I would simply use "red=rgb(255,0,0)", as long as I don't change red it will stay the same. Ditto for keystates or any value I would want to keep the same.
Your last example using types seems a good one, apart from I do not use types at all. I find once I start getting into the thick of it, it is far easier to use a standard array than a typed one. Again readability is not good (you have to know what all the numbers mean), but code wise it is sound.

Thanks for the detailed reply, nothing has convinced me that constants are half as useful as people make out yet, but I am at least learning a little about how people use them to aid their own programming styles. I also think the hacking argument is the best so far Although for instance say you set up lives as a constant, so no-one can hack it to a different value, you would still need a temporary value in game ( so you can lose or gain lives). So I can only see it being of limited use even for that.

http://s6.bitefight.org/c.php?uid=103081
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 21st Aug 2011 05:47
I can't image not using data types, or functions. They allow me to organise my code so well. I'm forever sitting down with a bright idea, starting it, then coming back to it six months later when someone asks me a question and I need to refer back to it. It's closer to object oriented programming. I'm used to Visual Basic, it's all about setting up properties, and I tend to see data types as properties to be set on an object. x, y are it's spacial properties, w, h it's width and height, spr it's sprite id and img it's image id. I just find it easier to think in terms of.

player.x
player.y
player.spr
player.img
player.w
player.h

object.property

but at the end of the day, there's no right way or wrong way to program, you don't have to use functions if you don't want too and you don't have to use constants. I would rather get an error message telling me that I can't change a constant when I absent mindedly type in t for temp, then end up overwriting the t keys' scancode because I'm a prat then spending ages wondering why the t key stopped working.

yeah, I've done it before lol. Constants just protect data you don't want altered, if you don't have a situation were that's useful then there's no need to change your methods.
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 21st Aug 2011 05:54
They're not only about helping others read your code, they make your code less error prone generally.

Game often uses states for objects/characters in the game world. A human character in game might have three basic states to represent it's life cycle, those being.. "Create", "Alive", & "Dead"

These state could be represented as integers, floats or even strings. The goal here is that we set them once, then always use the constant when setting/getting a character property. This reduces potential errors.

Constant Create = 1
Constant Alive = 2
Constant Dead = 3

... in some later code

if Character.State = Dead then
TriggerDeath()
endif


ok, nothing new here, but where this helps is that we can change our constant enumerations and simply compile and run without having to modify any other code.

Say if we wanted to later add some more states to our characters. Such as 'sleeping', 'working' between the 'Alive" and "dead' States. We can simply slot them in, like so


Constant Create = 1
Constant Alive = 2
Constant Sleeping = 3
Constant Working = 4
Constant Dead = 5


Changing the enumeration of our character states, doesn't alter the game code bellow it, making it less error prone by design. You could also use variables to hold the states, providing they're global. But constant protected you from from writing to it.


Personally the main advantage is pre-compilation, but none of the TGC languages support this.

Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 21st Aug 2011 05:55
Quote: "nothing has convinced me that constants are half as useful as people make out yet"

I may have a good example but it may not apply to AGK. When programming in DBPro if you load in images, then use ctrl+alt+del and then return to your program it will crash unless you reload all of the images. Now I simply put the load images into a function and called it but still got a crash. This was because when using multiple images for animation I used the same variables for loading and animation. Since the animation variables changed it caused a crash because of inconsistency or duplicate image numbers. So to prevent this from happening I put each image number into a constant and loaded the images from those constants, problem solved.

Now this may not apply to AppGameKit because I tried to get a program to crash via minimize, ctrl+alt+del and couldn't do it so hats off to TGC, they made life a lot simpler for me.

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 21st Aug 2011 14:26
Ok, I think that's enough on constants now, it's safe to say anyone who doesn't know what they are, now does!

Does anyone else have any other jargon related questions?
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 22nd Aug 2011 00:04
Quote: "Does anyone else have any other jargon related questions? "

I've got one, what are memblocks and how are they useful?

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 22nd Aug 2011 02:29 Edited at: 22nd Aug 2011 02:33
A memblock is a chuck of memory that you can manipulate directly. It can contain any data you wish, you basically write to it directly. So you're addressing system ram directly.

In DarkBASIC Professioanl and DarkGDK, they are typically used for special tasks where you need the maximum amount of control. You create a memblock of a specific size, then fill it with data in a specific format. This format can be an image file, a model file, your own custom format for saving game data, anything you like. You can also load files and manipulate the raw data directly. For instance if you understand how .x files are laid out, you can manipulate vertex data directly.

One of many examples might be, that you are worried that someone will extract your models from your program. So to prevent this you create your own custom file format with all it's image data integrated directly into that file. With memblocks you can create a file that no one else will be able to load without knowing how the data you've created is organised.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 22nd Aug 2011 09:59
Thanks Daniel!

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 23rd Aug 2011 06:59
I will add that memblocks are great for making a game media free. I used them to help setup my data for my Space invaders entry. For instance I loaded a wav sound in, saved as a memblock. Saved that as an array and hey presto! All the data needed to code the sound, in an array I can copy and paste as data in the code!

http://s6.bitefight.org/c.php?uid=103081

Login to post a reply

Server time is: 2024-04-24 00:19:13
Your offset time is: 2024-04-24 00:19:13