Programmers' Corner

Vulgotha

Power Member
Jan 6, 2007
15,776
148
0
28
#31
[QUOTE="Christopher, post: 6292901]I work with a number of professional programmers who don't either. Some of them are better programmers than me. Biggest difference? My student loan. sigh[/QUOTE]

Right in the feels.
 

John Willaford

Dedicated Member
Feb 28, 2013
1,050
17
0
Owings Mills, MD
#32
[QUOTE="Abdou23, post: 6290168]With very basic Java knowledge ( from some youtube tutorials ) what is the best way to learn Android developing ?![/QUOTE]

You need to work on some good Java first.
Then, head to developer.android.com

Most important on Android and Java GUIs is to SEE IT FIRST.
Design in your mind, then sketch it, then ofcourse turn your design some into some sort of data flow diagram or like tool to make sure it does what
 

John Willaford

Dedicated Member
Feb 28, 2013
1,050
17
0
Owings Mills, MD
#33
[QUOTE="Abdou23, post: 6290168]With very basic Java knowledge ( from some youtube tutorials ) what is the best way to learn Android developing ?![/QUOTE]

You need to work on some good Java first.
Then, head to developer.android.com

Most important on Android and Java GUIs is to SEE IT FIRST.
Design in your mind, then sketch it, then ofcourse turn your design some into some sort of data flow diagram or like tool to make sure it does what you want and that ofcourse helps to design the program.
Yeah, alot of people say sit and hack, but, it leads to some lots of recoding and missed intended features when your not careful.
 

WaxWeazle

Selected Members Council
Staff member
Jan 12, 2014
5,412
18
38
26
Belgium
#34
Have never been coding before, but am interested in looking into HTML & php, if I can get on my way with it, I might start looking into making an iphone app :)
But that's quite far ahead.. Let's just say, interested in, hoping to get a step further, meaning 'actually getting it' :D
 

Christopher

Community and Technical Manager
Staff member
Jun 1, 2007
11,921
96
48
48
Newnan, GA
#35
[QUOTE="WaxWeazle, post: 6293397]Have never been coding before, but am interested in looking into HTML & php, if I can get on my way with it, I might start looking into making an iphone app :)
But that's quite far ahead.. Let's just say, interested in, hoping to get a step further, meaning 'actually getting it' :D[/QUOTE]

I like PHP although I'm used to strongly typed languages. The nice thing though is that you can run PHP just about everywhere. I edit PSU.com code on my mac using PHPStorm (awesome IDE), which isn't free, but there are ton of free editors out there.

iPhone dev is a totally different animal. Objective C syntax is different than other C languages and you do have some memory management to contend with. iPhone SDK is a very rich library though.

Lots of good jobs out there for both PHP and iPhone. PHP is mostly used in web apps though so if you want to do web development that isn't a bad choice at all. I think most entry level programmers will find more opportunities in web development than device or SO dev these days.
 

F34R

Legend
Feb 11, 2008
40,317
430
83
South Carolina
#36
I agree with Chris 100%. Even with my limitations, I can still hold my own with PHP.

I can still do enough to get by with some simple things in other environments... iOS for example. Just takes longer for me to do it now. What would take a few hours, takes me a couple days. Let's say... a simple game. With all the assets already available, the coding took 4 hours, that's from start to a finished game. A simple one. Now, it took me a little over two days to get the same thing running properly.
 

MGSfan

Dedicated Member
Jun 24, 2005
1,142
3
38
29
#37
Java, C#, JavaScript, PHP, C a few more but I'm to lazy to write them down

My favourite is C#, using visual studio is a blast :)



Skickat från min GT-I9305N via Tapatalk
 

Christopher

Community and Technical Manager
Staff member
Jun 1, 2007
11,921
96
48
48
Newnan, GA
#38
[QUOTE="MGSfan, post: 6296698]Java, C#, JavaScript, PHP, C a few more but I'm to lazy to write them down

My favourite is C#, using visual studio is a blast :)



Skickat från min GT-I9305N via Tapatalk[/QUOTE]

Yep. Visual Studio is awesome. PHPStorm is pretty great as well.

Didn't know we had so many coders! :icon_thumright:
 

Shingo

Forum Guru
Dec 21, 2011
3,648
43
48
#39
[QUOTE="WaxWeazle, post: 6293397]Have never been coding before, but am interested in looking into HTML & php, if I can get on my way with it, I might start looking into making an iphone app :)
But that's quite far ahead.. Let's just say, interested in, hoping to get a step further, meaning 'actually getting it' :D[/QUOTE]
If you are only aiming for Iphone Apps , then skip all the rest and jump direct to xcode, because Objective C is unique, and nothing like others. Learning php or html won't help you much about that. ( at least as far as I know those ).

I personally would prefer learning objective c before anything else, It was the most stable and simple , because like no others, It only exists to develop on Ios.
 

Nerevar

Sonata Dusk
Staff member
Aug 27, 2005
10,637
179
63
Equestria
#40
I'm working on a basic text adventure game in Python.

It's a bitch to do, as my code runs linearly. I don't know how to do any parallel processes. I do have the code written that determines the outcome of battles, along with the introduction (where you choose your name, class name, and stats), but I'm not sure how to pull everything together to make it work.
 

Christopher

Community and Technical Manager
Staff member
Jun 1, 2007
11,921
96
48
48
Newnan, GA
#41
I wouldn't think parallel processing would be necessary. I think you probably just need to organize your code into classes. If you find you are creating a lot of If/Then conditionals then it is probably to linear and thus, more complex.

So, for example, if you have a character do you have a character class?

Can you give an idea of how your battle code works?
 

MGSfan

Dedicated Member
Jun 24, 2005
1,142
3
38
29
#42
[QUOTE="Rapture, post: 6296723]I'm working on a basic text adventure game in Python.

It's a bitch to do, as my code runs linearly. I don't know how to do any parallel processes. I do have the code written that determines the outcome of battles, along with the introduction (where you choose your name, class name, and stats), but I'm not sure how to pull everything together to make it work.[/QUOTE]

As Christopher said you'd be wise to start thinking object oriented. .it'll make your code more maintainable, dynamic and less of a pain to look at.

Skickat från min GT-I9305N via Tapatalk
 

Nerevar

Sonata Dusk
Staff member
Aug 27, 2005
10,637
179
63
Equestria
#43
[QUOTE="Christopher, post: 6296732]I wouldn't think parallel processing would be necessary. I think you probably just need to organize your code into classes. If you find you are creating a lot of If/Then conditionals then it is probably to linear and thus, more complex.

So, for example, if you have a character do you have a character class?

Can you give an idea of how your battle code works?[/QUOTE]

Well, it doesn't really matter how the battle code itself works. The issue is having specific sects of code be used when necessary. I need the player to be able to return places, have varied options available, make choices, etc. It's a hassle if the code is running linearly, and reusing while True: and if/elif functions over and over is becoming a pain.

I've read a little about modules, which I think is the Python equivalent of these classes you speak of. They would help, but I need to go learn them first.

If you're still wondering, the game would work like:

"You approach a split in the road. A sign stands nearby, exclaiming the left path goes to Thalme and the right path goes to cursed cave."
"Which way do you choose?"

[1] Left, to Thalme [2] Right, to the cursed cave [3] Back to old farmstead

>>> 1

"You chose to head towards Thalme. No doubt a safer choice, but who knows what opportunities the cave held."

(1/5 chance along this road a bandit will appear)

"Suddenly, along the quiet road to Thalme, a bandit emerges from the woods. He demands your purse and coin immediately."
"What do you do?"

[1] Assault [2] Hand over your money [3] Persuade [4] Observe [5] Flee

>>> 1

"You draw your sword and stare down the bandit. He shifts his feet nervously at the sight of the blade, but still brings forth his dagger in a determined way. He is not backing down."
"What do you do?"

[1] Attack [2] Inventory [3] Observe [4] Flee

>>> 1

Stuff like that. Then the battle code would go:
(It's a work in progress, so it's messy)

#Warrior:
#6 - Strength
#6 - Defense
#6 - Speed
#6 - Agility
#6 - Personality

#Player stats
strength = 6
defense = 6
speed = 6
agility = 6
personality = 6

#Enemy stats
enemy_strength = 6
enemy_defense = 6
enemy_speed = 6
enemy_agility = 6
enemy_personality = 6

print('A warrior skeleton has appeared!')

import time
time.sleep(2)

print('')
print('What do you do?')

while True:

print('[1] Attack [2] Inventory [3] Escape')
x = input()

if x == '1':
print('You move forward to slash the enemy!')
import time
time.sleep(1)

print('...')
import time
time.sleep(1)

player_attack_chance = speed + agility / 2
enemy_evasion_chance = enemy_speed / 2 + enemy_agility

rolled_chance = (player_attack_chance / enemy_evasion_chance)

final_chance = 0.5 / rolled_chance * 100

print(player_attack_chance)
print(enemy_evasion_chance)
print(rolled_chance)
print(str(final_chance)+'%')


from random import randrange
x = randrange(0, rolled_chance+1)#This needs work


if x > 0.5:
print('You\'ve hit your foe, doing X damage!')
elif x <= 0.5:
print('Your foe managed to dodge your attack!')





break

elif x == '2':
print('[Inventory]')
break

elif x == '3':
print('You attempt to flee!')
escape_chance = (speed + agility) / 2
import time
time.sleep(1)
print('...')
import time
time.sleep(1)
print('You\'ve escaped succesfully!')
break

import time
time.sleep(2)

print(''End of code')

The determination of basic evasion is so:

Your Attack / Enemy Evasion

Examples...

8 / 16 = 100% chance of miss
8 / 14 = 87.71% chance of miss
8 / 12 = 75.75% chance of miss
8 / 10 = 62.5% chance of miss

8 / 8 = 50% chance of miss
8 / 6 = 38.4% chance of miss
8 / 4 = 25% chance of miss
8 / 1 = 6.25% chance of miss
8 / 0 = 0% chance of miss

12 / 19 = 79.36% chance of miss
12 / 5 = 20.83% chance of miss



This is gauged easily.

Your Attack / Enemy Evasion = x
0.5 / x * 100 = Chance of missing

That's only a part of a single battle sequence. There's planned modifiers (potions, armor, etc) plus the attacks themselves (I'm thinking Attacker Strength - Defender's Defense = damage dealt). Then I have to code the response attack done by the enemy AI. Whoever can attack first is determined by the speed stat of the player and enemy.

The game is planned to have many fights, most being random and others placed. As you can see, this would create some very bulky code. And again, there's the issue of making this all work in a linear script.
 

mynd

Ultimate Veteran
May 3, 2006
20,814
170
63
46
Down Under
#44
I know a lot of languages, most of them obsolete LOL.

The relevant one is C++

API's

DirectX 8,9,11
FMOD

Tools:
Visual Studio (6, 2005, 2010)
Maya 7
Polytrans


Obsolete:
Logo, Z80-A Assembler, Locomotive Basic, Pascal.
 

MGSfan

Dedicated Member
Jun 24, 2005
1,142
3
38
29
#45
[QUOTE="mynd, post: 6296790]I know a lot of languages, most of them obsolete LOL.

The relevant one is C++

API's

DirectX 8,9,11
FMOD

Tools:
Visual Studio (6, 2005, 2010)
Maya 7
Polytrans


Obsolete:
Logo, Z80-A Assembler, Locomotive Basic, Pascal.[/QUOTE]

You wouldn't happen to know some C ? Need some help with a few assignments hehe?

Skickat från min GT-I9305N via Tapatalk
 

mynd

Ultimate Veteran
May 3, 2006
20,814
170
63
46
Down Under
#46
[QUOTE="Rapture, post: 6296761]Well, it doesn't really matter how the battle code itself works. The issue is having specific sects of code be used when necessary. I need the player to be able to return places, have varied options available, make choices, etc. It's a hassle if the code is running linearly, and reusing while True: and if/elif functions over and over is becoming a pain.

I've read a little about modules, which I think is the Python equivalent of these classes you speak of. They would help, but I need to go learn them first.

If you're still wondering, the game would work like:

"You approach a split in the road. A sign stands nearby, exclaiming the left path goes to Thalme and the right path goes to cursed cave."
"Which way do you choose?"

[1] Left, to Thalme [2] Right, to the cursed cave [3] Back to old farmstead

>>> 1

"You chose to head towards Thalme. No doubt a safer choice, but who knows what opportunities the cave held."

(1/5 chance along this road a bandit will appear)

"Suddenly, along the quiet road to Thalme, a bandit emerges from the woods. He demands your purse and coin immediately."
"What do you do?"

[1] Assault [2] Hand over your money [3] Persuade [4] Observe [5] Flee

>>> 1

"You draw your sword and stare down the bandit. He shifts his feet nervously at the sight of the blade, but still brings forth his dagger in a determined way. He is not backing down."
"What do you do?"

[1] Attack [2] Inventory [3] Observe [4] Flee

>>> 1

Stuff like that. Then the battle code would go:
(It's a work in progress, so it's messy)

#Warrior:
#6 - Strength
#6 - Defense
#6 - Speed
#6 - Agility
#6 - Personality

#Player stats
strength = 6
defense = 6
speed = 6
agility = 6
personality = 6

#Enemy stats
enemy_strength = 6
enemy_defense = 6
enemy_speed = 6
enemy_agility = 6
enemy_personality = 6

print('A warrior skeleton has appeared!')

import time
time.sleep(2)

print('')
print('What do you do?')

while True:

print('[1] Attack [2] Inventory [3] Escape')
x = input()

if x == '1':
print('You move forward to slash the enemy!')
import time
time.sleep(1)

print('...')
import time
time.sleep(1)

player_attack_chance = speed + agility / 2
enemy_evasion_chance = enemy_speed / 2 + enemy_agility

rolled_chance = (player_attack_chance / enemy_evasion_chance)

final_chance = 0.5 / rolled_chance * 100

print(player_attack_chance)
print(enemy_evasion_chance)
print(rolled_chance)
print(str(final_chance)+'%')


from random import randrange
x = randrange(0, rolled_chance+1)#This needs work


if x > 0.5:
print('You\'ve hit your foe, doing X damage!')
elif x <= 0.5:
print('Your foe managed to dodge your attack!')





break

elif x == '2':
print('[Inventory]')
break

elif x == '3':
print('You attempt to flee!')
escape_chance = (speed + agility) / 2
import time
time.sleep(1)
print('...')
import time
time.sleep(1)
print('You\'ve escaped succesfully!')
break

import time
time.sleep(2)

print(''End of code')

The determination of basic evasion is so:

Your Attack / Enemy Evasion

Examples...

8 / 16 = 100% chance of miss
8 / 14 = 87.71% chance of miss
8 / 12 = 75.75% chance of miss
8 / 10 = 62.5% chance of miss

8 / 8 = 50% chance of miss
8 / 6 = 38.4% chance of miss
8 / 4 = 25% chance of miss
8 / 1 = 6.25% chance of miss
8 / 0 = 0% chance of miss

12 / 19 = 79.36% chance of miss
12 / 5 = 20.83% chance of miss



This is gauged easily.

Your Attack / Enemy Evasion = x
0.5 / x * 100 = Chance of missing

That's only a part of a single battle sequence. There's planned modifiers (potions, armor, etc) plus the attacks themselves (I'm thinking Attacker Strength - Defender's Defense = damage dealt). Then I have to code the response attack done by the enemy AI. Whoever can attack first is determined by the speed stat of the player and enemy.

The game is planned to have many fights, most being random and others placed. As you can see, this would create some very bulky code. And again, there's the issue of making this all work in a linear script.[/QUOTE]

Ahhh text adventures, cut my teeth year sand years ago...


If you can understand a little basic, you should be able to rip through the structure of this book.

Anyway, just like any game programing your going to need a structure which you can navigate.
If you stop thinking of things in terms of linear progression you'll get there.

When I first wrote my first text adventure I was very naive and simply had line after line of codes and if, then goto commands.

Trust me you will go bonkers doing it this way and it will get very messy very quickly.

Firstly, think of you location in the world as simply a memory address.
All the information about this world should be at this place, should be at that memory location.
Learn a way to encapsulate what you want to do or say, in the most efficient way at that memory address, if you find you self repeating the same data a lot, reference that data vs repeating it over and over again.

When you let the character move left or right or forward then they move to another address.
Start thinking of each as exactly the same data.

E..g. Lets say you start in a wooded forest, you can go north south and east but not west. At this location you can see a bag of gold and a tree stump with an axe in it.

Ok, so what do you need you need to be able to write this as all data at that location.
There are lots and lots of ways to do this, C and C++ can uses structs, or class's, I'm sure python/java have something similar.

Looking at pseudo code I'd do it something like this

Struct LOCATION
{
pointer Exits [6]
Text Description
pointer Items[6]
}

This is fairly basic, but I've given you up to six exits (N,S,E,W, UP , DOWN), and up to six items you can place, as well some text to describe you location, and up to 6 items that can be at this place.

Things to note, the pointer Exits is a reference to the next location, if you don't want them to go that way then put 0, and handle it in your code.

Eg you code might look like this

Loop for game world:

Print Location[place]description (this is you text you typed into this location, eg. "You are in a Forrest")
Print "You can go "
if Location[place].Exits[0]<>0 ", North"
if Location[place].Exits[1]<>0 ", South"
if Location[place].Exits[2]<>0 ", East"
if Location[place].Exits[3]<>0 ", West"
if Location[place].Exits[4]<>0 ", Up"
if Location[place].Exits[5]<>0 ", Down"

Please note I'd normally just loop that last info in a for next loop but I'm trying to show it for teaching purposes.
This is automatic, its quite beautiful in it's simplicity because all you do is change the variable "place" and you have a new location with automatic printing of where you are and what exits are available.

If a player types in West or East etc, you can check against it being 0, if its 0 you can say "your not allowed that way", if its not, then you update the "place" variable with the data in you exit.

eg. Your at place 5, You exits might be north and south only. So you exits data will look like


Location[5].Exits[0]=6 -traveling north will go to location 6
Location[5].Exits[1]=4 -traveling south will go to location 4
Location[5].Exits[3]=0 - The rest are all zeros you can go that way.
Location[5].Exits[4]=0
Location[5].Exits[5]=0

The other thing to note was that I didn't use a text for the items at the location, because they are items. You may want to modify or take them, Instead I used a reference or pointer to another location that would hold that specific item data

EG. Item data might be:

Item
{
Text "Description"
Int Damage
Int Power
Int Weight
}
etc.

So in our example we had an axe and some gold at the location.
We a referencing them by saying at locaiton one is item[1] and item [2]

So our data will be added to our main game loop as:

Print "you can see "
If Location[place].Item[0]<>0 Print Location[place].Item[0]
etc (up to 6 as that's how may I gave you).

That way it will now say "You can see, an axe, a bag of gold> etc.

Now the beauty is if you have a get command, you can say...get bag of gold.
And then you would make that item=0 in your location (meaning it wouldn't say its at the location anymore.
But also you can add it to you inventory like this).

First you'd make some way of being able to translate what they asked into the item:

eg.

If input (first 3 characters"="Get"), then:
{
If (next word)=Location[place].Item[0]description then
{

Player.Inventory=no of items+1 //add 1 to the no. of items your carrying
Player.Inventory[no of items]=Location[place].Item[0] //transfer
Location[place].Item[0]description=0 //remove the item at the location.
}

And bang, you axe is now in your inventory.

Now a few things to note about all of this, in many ways choosing the options thing you're doing eg press 1,2,3 etc will mean you are not going to worry about handling text.
So what you need to to is decide exactly what options you provide.
Try and think of all of them:

N,E,W,S,Up, Down, Get, Give, etc etc and again wirte the code so that potentially all of those are possible. Then modify you "location data" to suit with options to opt out of said option.

eg No items are here, don't give them the "get" option.

Start thinking like that and it will all fall into place, battles are simply an extension of this, you can treat enemies in much the same way as you do items.

Everything is simply a memory location with data referencing what you what to be represented, get that in a decent structure, and then you can modify, toy with make up any world you want, as long as you start by making sure your structure accounts for all your possibilities.
 
Last edited:

mynd

Ultimate Veteran
May 3, 2006
20,814
170
63
46
Down Under
#47
[QUOTE="MGSfan, post: 6296822]You wouldn't happen to know some C ? Need some help with a few assignments hehe?

Skickat från min GT-I9305N via Tapatalk[/QUOTE]

you cant learn c++ without c, but I couldn't tell you what options aren't available in C.
Most of its is similar, structs etc .
 

Christopher

Community and Technical Manager
Staff member
Jun 1, 2007
11,921
96
48
48
Newnan, GA
#48
[QUOTE="Rapture, post: 6296761]Well, it doesn't really matter how the battle code itself works. The issue is having specific sects of code be used when necessary. I need the player to be able to return places, have varied options available, make choices, etc. It's a hassle if the code is running linearly, and reusing while True: and if/elif functions over and over is becoming a pain.

I've read a little about modules, which I think is the Python equivalent of these classes you speak of. They would help, but I need to go learn them first.

If you're still wondering, the game would work like:

"You approach a split in the road. A sign stands nearby, exclaiming the left path goes to Thalme and the right path goes to cursed cave."
"Which way do you choose?"

[1] Left, to Thalme [2] Right, to the cursed cave [3] Back to old farmstead

>>> 1

"You chose to head towards Thalme. No doubt a safer choice, but who knows what opportunities the cave held."

(1/5 chance along this road a bandit will appear)

"Suddenly, along the quiet road to Thalme, a bandit emerges from the woods. He demands your purse and coin immediately."
"What do you do?"

[1] Assault [2] Hand over your money [3] Persuade [4] Observe [5] Flee

>>> 1

"You draw your sword and stare down the bandit. He shifts his feet nervously at the sight of the blade, but still brings forth his dagger in a determined way. He is not backing down."
"What do you do?"

[1] Attack [2] Inventory [3] Observe [4] Flee

>>> 1

Stuff like that. Then the battle code would go:
(It's a work in progress, so it's messy)

#Warrior:
#6 - Strength
#6 - Defense
#6 - Speed
#6 - Agility
#6 - Personality

#Player stats
strength = 6
defense = 6
speed = 6
agility = 6
personality = 6

#Enemy stats
enemy_strength = 6
enemy_defense = 6
enemy_speed = 6
enemy_agility = 6
enemy_personality = 6

print('A warrior skeleton has appeared!')

import time
time.sleep(2)

print('')
print('What do you do?')

while True:

print('[1] Attack [2] Inventory [3] Escape')
x = input()

if x == '1':
print('You move forward to slash the enemy!')
import time
time.sleep(1)

print('...')
import time
time.sleep(1)

player_attack_chance = speed + agility / 2
enemy_evasion_chance = enemy_speed / 2 + enemy_agility

rolled_chance = (player_attack_chance / enemy_evasion_chance)

final_chance = 0.5 / rolled_chance * 100

print(player_attack_chance)
print(enemy_evasion_chance)
print(rolled_chance)
print(str(final_chance)+'%')


from random import randrange
x = randrange(0, rolled_chance+1)#This needs work


if x > 0.5:
print('You\'ve hit your foe, doing X damage!')
elif x <= 0.5:
print('Your foe managed to dodge your attack!')





break

elif x == '2':
print('[Inventory]')
break

elif x == '3':
print('You attempt to flee!')
escape_chance = (speed + agility) / 2
import time
time.sleep(1)
print('...')
import time
time.sleep(1)
print('You\'ve escaped succesfully!')
break

import time
time.sleep(2)

print(''End of code')

The determination of basic evasion is so:

Your Attack / Enemy Evasion

Examples...

8 / 16 = 100% chance of miss
8 / 14 = 87.71% chance of miss
8 / 12 = 75.75% chance of miss
8 / 10 = 62.5% chance of miss

8 / 8 = 50% chance of miss
8 / 6 = 38.4% chance of miss
8 / 4 = 25% chance of miss
8 / 1 = 6.25% chance of miss
8 / 0 = 0% chance of miss

12 / 19 = 79.36% chance of miss
12 / 5 = 20.83% chance of miss



This is gauged easily.

Your Attack / Enemy Evasion = x
0.5 / x * 100 = Chance of missing

That's only a part of a single battle sequence. There's planned modifiers (potions, armor, etc) plus the attacks themselves (I'm thinking Attacker Strength - Defender's Defense = damage dealt). Then I have to code the response attack done by the enemy AI. Whoever can attack first is determined by the speed stat of the player and enemy.

The game is planned to have many fights, most being random and others placed. As you can see, this would create some very bulky code. And again, there's the issue of making this all work in a linear script.[/QUOTE]

Yeah, I would seriously look into an object-oriented approach. Python does have classes and I don't think they are the same as modules. From what I read, modules are libraries of code that can be imported. Your "time" reference is a module. Classes are ways to encapsulate attributes and behaviors in a class that are easily reused. So if I had a Player class, for example, then I could have all the attributes (strength, defense, speed, etc.) of that Player within the class. Your Player class could have built in functions like "Attack". So say I also had an Enemy class with its own attributes. So if I spin up my objects using these classes like this...

warrior = Player()
skeleton = Enemy()

...I can now program inside the objects and give them behaviors. So now my code starts to read like a sentence, for example.....

warrior.Attack(skeleton)

Not sure if this syntax works entirely for Python, but that is the basic idea. Of course, you would initialize your Player object during startup of your program and you would have to set all your attributes, etc. And the above is just one way to do it. There may be better ways to handle "attacking" and whatever in separate classes. It all kinda depends.

You could then have other classes that interact with these to handle the map and moving between areas and stuff like that. It can be complicated at first, but once you wrap your head around it, it just makes sense.

Hope this helps.
 

mynd

Ultimate Veteran
May 3, 2006
20,814
170
63
46
Down Under
#49
Personally I think class's is probably going a bit to far, but structured arrays is ideal.
Arrays arrays arrays....

That's just a fancy way of saying treat all these memory location in a specific way BTW.
 

Christopher

Community and Technical Manager
Staff member
Jun 1, 2007
11,921
96
48
48
Newnan, GA
#50
[QUOTE="mynd, post: 6296861]Personally I think class's is probably going a bit to far, but structured arrays is ideal.
Arrays arrays arrays....

That's just a fancy way of saying treat all these memory location in a specific way BTW.[/QUOTE]

I'd rather not have to keep up with indexing.

Player.strength

rather than....

Player[5]

edit: or I guess you would use a constant, wouldn't you?

const strength=5
player[strength]

If a program has any sort of complexity, I'm going to use classes every time. Personal preferences vary, of course.
 

mynd

Ultimate Veteran
May 3, 2006
20,814
170
63
46
Down Under
#51
[QUOTE="Christopher, post: 6296876]I'd rather not have to keep up with indexing.

Player.strength

rather than....

Player[5]

edit: or I guess you would use a constant, wouldn't you?

const strength=5
player[strength]

If a program has any sort of complexity, I'm going to use classes every time. Personal preferences vary, of course.[/QUOTE]

Well struct gives you that ability without out classes.
Technically a class is simply a super struct with the ability to not only call data, but also code.

There is no difference referencing

Player.strength in a struct to a class.

The difference comes when you want to run a subroutine
eg

Player.minushealth()

isn't possible in a struct.


Although stuct form my understanding it not available in Python, which just plain sucks.
 

Christopher

Community and Technical Manager
Staff member
Jun 1, 2007
11,921
96
48
48
Newnan, GA
#52
[QUOTE="mynd, post: 6296888]Well struct gives you that ability without out classes.
Technically a class is simply a super struct with the ability to not only call data, but also code.

There is no difference referencing

Player.strength in a struct to a class.

The difference comes when you want to run a subroutine
eg

Player.minushealth()

isn't possible in a struct.


Although stuct form my understanding it not available in Python, which just plain sucks.[/QUOTE]

Why does that suck? You can accomplish the same thing as struct with a class, as you pointed out. Use static fields and it is a class on the stack. Structs are hold-overs from C. Not really necessary in newer languages.
 

mynd

Ultimate Veteran
May 3, 2006
20,814
170
63
46
Down Under
#53
[QUOTE="Christopher, post: 6296917]Why does that suck? You can accomplish the same thing as struct with a class, as you pointed out. Use static fields and it is a class on the stack. Structs are hold-overs from C. Not really necessary in newer languages.[/QUOTE]
Depends, there are lot so good reasons to use structs, especially as they are inline.
Hell I uses stucts inside class's at times, I'd go so far to say my 3d engine wouldn't run without them.
Plus soon as your data is in a class, its private. Which can mean an unnecessary interface just to get some data out.

[video=youtube;qJ4Kzk6mnFc]http://www.youtube.com/watch?v=qJ4Kzk6mnFc&safe=active[/video]

Its lightweight, and can be used relatively easily inside a class.
 
Last edited:

Christopher

Community and Technical Manager
Staff member
Jun 1, 2007
11,921
96
48
48
Newnan, GA
#54
[QUOTE="mynd, post: 6296924]Depends, there are lot so good reasons to use structs, especially as they are inline.
Hell I uses stucts inside class's at times, I'd go so far to say my 3d engine wouldn't run without them.
Plus soon as your data is in a class, its private. Which can mean an unnecessary interface just to get some data out.

[video=youtube;qJ4Kzk6mnFc]http://www.youtube.com/watch?v=qJ4Kzk6mnFc&safe=active[/video][/QUOTE]

Variables in classes can be public or private in most languages. But I'll defer to you as far as structs usefulness in C/C++. They are basically the same thing as data objects in other languages.
 

mynd

Ultimate Veteran
May 3, 2006
20,814
170
63
46
Down Under
#55
[QUOTE="Christopher, post: 6296931]Variables in classes can be public or private in most languages. But I'll defer to you as far as structs usefulness in C/C++. They are basically the same thing as data objects in other languages.[/QUOTE]

They have their place, trust me.
In the case above I was using them simply because it's relatively easy to access, and I'm not sure he wants to go through the whole class thing just yet.
 

Christopher

Community and Technical Manager
Staff member
Jun 1, 2007
11,921
96
48
48
Newnan, GA
#56
[QUOTE="mynd, post: 6296933]They have their place, trust me.
In the case above I was using them simply because it's relatively easy to access, and I'm not sure he wants to go through the whole class thing just yet.[/QUOTE]

Yeah, there are a thousand different ways to tackle a problem. In my mind, objects make life easier. But to each their own.
 

Abdou23

Forum Elder
Sep 16, 2008
2,757
10
0
Egypt
#57
I decided to jump into the App development wagon, i've been thinking to do do for over 4 months now, and i even watched some youtube videos and learned some Java basics. But now that i'm fully ready to take that step i would like to know which is better and/or easier for learning: C then Objective C or Java then Android. I understand that both Java and C are very similar but from what i've been gearing it's better to develop for ios.
And what exactly are my chances into succeeding in this world ? yes i have the well and the time but how long will it take me to be able to create a decent app. ?!

I found this online courses website and it seems very respectable, i might start there. Udemy
 

Christopher

Community and Technical Manager
Staff member
Jun 1, 2007
11,921
96
48
48
Newnan, GA
#59
I'm not sure how much learning C will help with Objective C. The differences between C and Objective C syntax is significant and it is a slightly different approach in programming. iPhone development is bit more structured as it has a MVC architecture built in. So you really need to understand MVC more than you need to know the C language to be prepared for iPhone development, imo. After that, understanding how to retain and release resources is the next hurdle, which is also done differently (at least in syntax) in Objective C.

I think iOS probably is the more sought after skill set for mobile devices, but I don't have anything to back that up. Just a gut feel. But the advantage of Android development is that Java is simply easier to program than any C language. Java has built in memory management so you don't have to worry about the retaining/releasing. Also, everything in Java is pass by value rather than value or reference. That may seem like nothing, but pointers and memory addressing is something that has given novice programmers fits in my experience. mynd can speak to this more accurately than I can though. I may be overstating it.

Another option to consider is Mono Touch. Program for both devices using C#.

As far as courses, I would check out iTunes U. I watch a number of courses that Stanford put on iTunes for iPhone development. Excellent college level courses......free.
 

Abdou23

Forum Elder
Sep 16, 2008
2,757
10
0
Egypt
#60
I really can't make up my mind,But from what i read i understand that C is preferable to learn before Objective C ( i'm talking basics of course ) same goes to Java. If there is a way to create native apps for both Android & ios using only one language that would've been awesome ( not c# thou :), )

But another important question now is how long it will take me to be able to make a professional App ?! say i can learn a certain language in a week or two according to the online courses.