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.

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,875
made a list and added .append with weapon. Works now. Need to test it though.
Bit different to what i had in mind but works just with additional for loop

as of :

name = weapon_create("jolly swing")

My point was more something like this:

input from keyboard string
That string then would became variable name and name for weapon at the same time.

so for example :

Type your weapon name: I type "petronas"

Then it would create variable called petronas which would be directory and in that directory there would be name with "petronas" string :

petronas = {}
then petronas = {"name" :"petronas"}

Whole point is that you can't use variable that is string for directory as it is immutable(that is what i read). So to create variable you would need to convert string to non string and state it as variable. Then that variable would work for directory name.

so if you for example state

variablea = "string"

then you can't use:

variablea["something"] = "something else"


===
 
Last edited:

k-t

Novice
Joined
Oct 29, 2012
Messages
18
variablea = "string"

then you can't use:

variablea["something"] = "something else"

Well, you still can write it this way:

Code:
variablea = "string" # create a string object with a value "string", point it to variablea
variablea = {}        # create a dictionary object, point it to variablea. previous string object will stay in memory and will be garbage collected at some point
variablea["something"] = "something else" # now variablea references dictionary object and we can use [] operator

And it will work. But as everyone else said above, it doesn't make any sense. As I presume from your explanation, you just confuse variables with values they represent.
 

28.8bps Modem

Prophet
Joined
Jan 15, 2014
Messages
302
Location
The Internet, Circa 1993
If I understand it, you want to have a dictionary of dictionaries, so:

Code:
def create_weapon(directory, name):
    directory[name] = { attribute : value }

directory = dict()
create_weapon(directory, "bow of smiting")
create_weapon(directory, "dagger of maiming")

or equivalently:

Code:
def create_weapon(directory, name):
     directory[name] = dict()
     directory[name][attribute] = value

directory = dict()
create_weapon(directory, "bow of smiting")
create_weapon(directory, "dagger of maiming")
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,875
GOAL2 achieved ! ========================================



I am super happy with weapon generator script. Tomorrow i will think about GOAL3. I think it will be C# syntax learning.
Any good books for beginners ? Or maybe something like codeacademy ?


Compiled program: weapongenerator (inside it run weapon_generator.exe)
you will need: python 2.7.8
pure .py file: weapon_generator.py

raw code:

Code:
import random

# weapon material its weight and price
weapon_materials = ['gold', 'silver', 'iron', 'bronze', 'steel', 'obsidian']
weapon_materials_weight = {
    'gold': 70,
    'silver': 50,
    'iron': 40,
    'bronze': 30,
    'steel': 50,
    'obsidian': 20
}
weapon_materials_price = {
    'gold': 20,
    'silver': 13,
    'iron': 5,
    'bronze': 2,
    'steel': 9,
    'obsidian': 1,
}

# weapon type, sharpness, weapon weight modifier and weapon type price
weapon_types = ['flail', 'longsword', 'shortsword', 'spear', 'warhamer', 'mace']
weapon_type_sharpness = {
    'flail': 10,
    'longsword': 50,
    'shortsword': 50,
    'spear': 100,
    'warhamer': 10,
    'mace': 20
}
weapon_type_weight_mod = {
    'flail': 10,
    'longsword': 5,
    'shortsword': 3,
    'spear': 3,
    'warhamer': 20,
    'mace': 15
}
weapon_type_price = {
    'flail': 3,
    'longsword': 7,
    'shortsword': 4,
    'spear': 1,
    'warhamer': 1,
    'mace': 5
}

# FUNCTIONS

def make_weapon(name):
    weapon = {}
    weapon["name"] = name
    weapon["type"] = random.choice(weapon_types)
    weapon["material"] = random.choice(weapon_materials)
    weapon["damage"] = weapon_materials_weight[weapon["material"]] * weapon_type_weight_mod[weapon["type"]] + weapon_type_sharpness[weapon["type"]]
    weapon["weight"] = weapon_materials_weight[weapon["material"]] * weapon_type_weight_mod[weapon["type"]]
    weapon["price"] = weapon_materials_weight[weapon["material"]] * weapon_type_weight_mod[weapon["type"]] * weapon_materials_price[weapon["material"]]
    return weapon_list.append(weapon)

def weapon_description(list_with_weapons):
    for weapon in list_with_weapons:
        print
        print "The %s | %s %s" % (weapon["name"], weapon["material"], weapon["type"])
        print "===== STATS ======"
        print "damage   - ", weapon["damage"]
        print "weight   - ", weapon["weight"], "|O"
        print "price    - ", weapon["price"], "G"
        print

# VARIABLES

weapon_list = []

# WEAPON GENERATOR CODE BELOW

print "============================="
print "=      WEAPON GENERATOR     ="
print "============================="
print
print "==================================================================================="
print "= Upon naming weapon this program will first create weapon from TYPE and MATERIAL ="
print "=        Then it will calculate stats of weapon: DAMAGE , WEIGHT, PRICE           ="
print "==================================================================================="
print

weapon_created = raw_input("name your weapon : ")
make_weapon(weapon_created)
weapon_description(weapon_list)


raw_input("")
 
Last edited:

baturinsky

Arcane
Joined
Apr 21, 2013
Messages
5,537
Location
Russia
Key to art of programming is containing complexity. As you add things to your code, it should not exceed complexity that you, computer or user can deal with. All that classes, strong typing, tests, yadda yadda are needed for when you have already a lot of code, it should still be simple enough to maintain, debug and add things too. And if you will need to do more things per tick (AI, graphics and physics tend to be particularly resource-heavy) you will have to optimize your code to fit in your PC capabilities. And last thing, that is often forgotten about, you should keep things simple for user too. Player should understand how things in game work, so he can know what to expect from them and how to "play" them.
 

almondblight

Arcane
Joined
Aug 10, 2004
Messages
2,549
petronas = {}
then petronas = {"name" :"petronas"}

Whole point is that you can't use variable that is string for directory as it is immutable(that is what i read). So to create variable you would need to convert string to non string and state it as variable. Then that variable would work for directory name.

Dictionary keys can't be mutable; strings are immutable, so they're fine. weapons["petronas'] = {"name": "petronas"} works.
 

CreamyBlood

Arcane
Joined
Feb 10, 2005
Messages
1,392
Any good books for beginners ? Or maybe something like codeacademy ?
I went through a few C# books, some less dry than others. I liked this one best because it wasn't so boring. You might skim a few chapters. I also skipped the Windows 8 stuff but the rest of it kept me interested.

Head First C#, 3rd Edition
http://shop.oreilly.com/product/0636920027812.do

Of course, I still don't know what the heck I'm doing, I'm still just a hack so maybe it isn't so good after all.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
I am not sure I really understand what you are trying to accomplish here. But most likely it can be done with objects:


Weapon weapon = new Weapon("Dagger", true);
Weapon weapon = new Weapon("Sword", true);
..

class Weapon
//constructor:
public Weapon(string Name, bool randomize)
{
this.Name=Name;
if(randomize)
{
Randomize();​
}​
}​
}

??
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,875
Ok i am back !
Now what IDE should i use for C# ? Ton of people seems to think that i should use VS...

edit: installing VS2013
 
Last edited:

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,875
also any good book for C# ? I assume there is no virtual training program like python one due to it being compile instead of jit.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,875
Will it even run on Win7 64bit ?

Also i noticed in 2013 you can just choose which net you want to use.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
Idk, I assume you need to specify if you want to make 32 or 64 bit applications.
If you choose 64 bit applications you could have problems with older IDE's.
I would save myself the hassle and stick to 32 bit.
You can later move your projects to a newer version, they will automatically import them. Does not take more than a minute.
Whenever you move to a new version you should know why you would need that. 2005 is 100 times faster and does not come with all the crap (WPF etc). I am still using it for all my work.
Newer dotnet versions have a few gimmicks like optional parameters, but it's not really necessary.
They are also designed with Micrsosoft greatest dead duck (WPF) in mind.
So yeah, you could benefit from some very subtle language improvements, but beware, everything that moves you an inch towards WPF is madness.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,875
ok thanks

Fuck looks like again i have two days off from my calendar. Fucking halloween and family. I though being jobless supposed to be all about free time !

edit:

Looks like 2005 is not compatible with win7. I'll try with compatibility tto winxp,

edit2:
nope run as admin + winxp comp didn't help. Debugger is installed but express not.
 
Last edited:

Raghar

Arcane
Vatnik
Joined
Jul 16, 2009
Messages
22,697
Frankly I think you should either start with Java, or use C++ without template metaprogramming, when you are just learning. OpenJava 7 makes it trivial to run stuff on Linux and W7 simultaneously, and you will stop worry about x64, or something else. As Burning Bridges said, .NET higher than 2.0 is a crap full of bloat and not exactly reasonable for learning.

If you use C++, set compiler to make target to x64, and I think there is an import in new standard that forces int to have 32 bits, and long 64 bits. Well I wasn't able to find it, so it's probably do it yourself and use compiler datatypes like __int64 .



To sum it up. For learning Object Oriented stuff you have these three alternatives each with some advantages and MAJOR disadvantages.
In Java.
You can install IDE, and do stuff immediatelly, have recompilation done after every type on keyboard, and then simply hit run and see application at full speed in optimized mode. You have rigidly defined standard data types. It has excellent documentation for standard library, and these tutorials are not bad when used for reference.
Of course, deployment isn't done by exe files, it wouldn't be crossplatform. And talking between Java and native libraries is done through JNI, which means you either need C++ compiler, or ASM. (ASM works better when you know what you want and know what you are doing.)

In C++
When you PIRATE MSVC latest version, the installation is relatively straightforward and it finally adheres to some standard. (Perhaps it's even C++ standard.) You can create fully EXE files, and viruses as your heart desires, and you can use ASM commands when you want to find number of ticks in high speed timer, or do something that should be in C++ standard and isn't. Also you have a lot of compilation options and you can play with compiler switches and testing your programs for days. That's amazing entertainment, some programmers are also calling it a work.
Of course, setting compilation properties can be a pain. Just you wait until you would need to type something into compiler/linker settings to be able to compile and link your program without errors. It has also major pain called data types doesn't have rigidly defined standard sizes, which they could do in C+00 standard, and they didn't. But they introduced "auto".


In C#.
You can have exe files, which are actually launchers that ask compiler to look for previously compiled exe files. (And generate them at runtime when they are not present, which can cause some hiccups.) You have rigidly defined standard data types. (note signed byte is called sbyte, signed int is called int)
It doesn't end with .NET 2.0, sooner or later would MS force on you PC bloated 480 MB crap .NET 4.0, and all these "security" patches. Installing IDE to work properly with version you want to use can be a pain. And also it's bad copy of Java that encapsulates byte code into executable container. (which is vulnerable to viruses, and still need compilation.)
Also it's from MS, which means they could say, we don't care about support anymore, and you'd be forced to change your programs to support insane bloatware .NET 5.0, witch all additional security features which would seriously complicate your work.
 

JMab

Augur
Joined
Nov 12, 2013
Messages
177
Location
Melbourne, Australia
VS2013 Express is perfectly fine. The "flat" WPF UI takes some getting used to, but given VS is the #1 IDE for game development, you should get used to it. Microsoft insist on eating their own dog food, if nothing else.

There is no need to pirate the professional version of VS. You'll get everything you need as a lone dev in the Express version. You'll be able to target C++ or C#, or even mix both, i.e. C++ engine and C# world editor is common.

Even though it's no longer recommended by MS, you can even keep using the .NET version of C++, C++/CLI which will give you the easiest interop to native C++, with IJW (It Just Works!).

You can target 32 and 64 bit. You can even target your app to be native Win8, but I'd recommend with sticking to plain, native C++, using portable data types wherever possible. That way you leave open the possibility of porting to other non-MS platforms at some point in the distant future!

On targeting 64 bit Windows, ints and longs are still 32 bit, you need to use the 64 bit equivalent. I tend to use the standard data types, e.g. int32_t, int64_t, etc. One thing to watch out for is that the standard size type, size_t, will compile to either 32 or 64 bit, so it's not recommended to use as a type for serialization/deserialization.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
Yes, VS is entirely free (you normally don't need more than Express, not even if you are developing professionally).

JMab Why the hell use int64? Why not simply use long?
 

28.8bps Modem

Prophet
Joined
Jan 15, 2014
Messages
302
Location
The Internet, Circa 1993
Yes, VS is entirely free (you normally don't need more than Express, not even if you are developing professionally).

JMab Why the hell use int64? Why not simply use long?

Because long is only guaranteed to be at least 32 bits. the (u)int family of typedefs are all of guaranteed width across compilers, which generally means you'll use them in circumstances where the field needs exactly the specified number of bits, for example using a uint32 where you're using the top couple of bits as switches, then the remaining length as its value.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
Are you talking through a time machine from 1993? We are talking about Visual Studio 2013 and int is 32 bits, long is 64 bits
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
You can use int32 unless you expect your variable to exceed -2,147,483,648 to 2,147,483,647
Int64 is for cases –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Consider the following example. Just use short or int.

Code:
Int64 popamole=3;
for(Int64 i=0; i<=popamole; i++)
{
//..
}
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
Perkel
would you be interested in a little longer C# code? I think it could teach you a few things, and could also be very useful for a game.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,875
what do you mean by that ? I mean if it will help me then yes but i would wait with after i would learn C# syntax and basic keywords/functions. As i said already i will be returning to learning after hallowen as i don't have that much time currently.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
Good.
I wanted to give you a longer piece of code that I find very useful. No problem if you are not ready.
 

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