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.

k-t

Novice
Joined
Oct 29, 2012
Messages
18
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

He is talking about C++. If you have any doubts just write a simple C++ program that prints sizeof(long) in VS2013.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
I thought we were talking about C#.

But ok Perkel:
data types have a maximum value depending on how much bits are available.
You can check eg with int.MaxValue()

If you reach MaxValue()+1 there will be an overflow, meaning they start at zero or a negative value again.
This was really important when integers were just 16 bits long, which is only 32768 values.

But nowadays this is no problem unless you need > ca 2*10^9
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,857
I never asked about 32bit-64bit integers i simply said VS2005 express seems to be incompatibile with Win7-x64 and you guys started to talk about things i simply can't understand yet as i am not yet in position to write code with such a big values.

As i said for now shitty holydays and after that we are back to business.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
just stick with int and you are fine, at least in C#.
I think the confusion comes from C++ users which give you advice that you don't need.
As datatype use bool, int, double, string
they are absolutely sufficient for almost everything you will do.
rarely needed: float, short, byte, long
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
The problem with integer overrun is something that you should understand though. On systems with 16 bit integers you can easily reach siutations where a simple addition could return completely wrong results.
This applies to C# as well.

Code:
short a = 32000; // short is int16
a += 32000;
Then go into the debugger: a = -1536 !

Code:
int b = 2000000000; // b is int32
b += 2000000000;
//b = -294967296
 
Last edited:

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,857
I guess you are right about that but I am not planning on getting any big values for my variables anytime soon.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
This isn't even complicated. Data is stored in bytes

1 byte is 8 bit
2 byte is 16 bit
3 byte is 24 bit
4 byte is 32 bit
8 byte is 64 bit

that's how computers work.
You already worked with hex editors. FF is 1 byte and it contains the value 255.
FF FF is 2 bytes and it contains the value 65535. And so on

Whenever you define the data type for a variable you only tell the compiler how many bytes to use for the variable
byte => 1 byte
short => 2 byte
int => 4 byte
long => 8 byte
and more bytes = can store larger values.
The only problem is this not the same in every environment. Many still use int => 2 byte.
And that's something you got to know as a programmer.

That's all there's to it.
 
Last edited:

Ninjerk

Arcane
Joined
Jul 10, 2013
Messages
14,323
Perkel, although I didn't read all the way through it, the book "Code" is a good read for a general view at how computers work. I don't remember who wrote it, but it's published by Microsoft.
 

Ninjerk

Arcane
Joined
Jul 10, 2013
Messages
14,323
Perkel, although I didn't read all the way through it, the book "Code" is a good read for a general view at how computers work. I don't remember who wrote it, but it's published by Microsoft.

this one?
http://www.amazon.com/Code-Language...s&ie=UTF8&qid=1414513279&sr=1-1&keywords=Code
That one. It has some basic things that he might not know like what a byte actually is, logic tables, etc. The little I read has put me conceptually ahead of the classes I'm taking. For some reason, the university I attend places logic after programming, but we are already making conditional statements that would greatly benefit from instruction in it.

EDIT: And actually, just yesterday I took a lab exam for that class (they are really easy). I finished (probably) 5 minutes before this 18 year old in the class who's a bit of a supreme gentleman and been coding since he was 12 years old (mind you, we're the first two done). I accidentally made a correct loop probably because I have some familiarity and can think a few steps ahead about how the logic has to work in the program I am making. This is not something a hobby programmer would pick up, I should think, unless they know to look for it in coding literature or stackoverflow or something like that.
 
Last edited:

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
Yes this sounds like a great book, probably will read this. And I agree most courses teach only language concepts that have little to do with how computers work, and lead to problems as I described above.
 

JMab

Augur
Joined
Nov 12, 2013
Messages
177
Location
Melbourne, Australia
Yes, sorry, I thought the latest goal was a C++ text adventure - I understand it's a C# something now?

Anyway, I'd agree that there are few uses for 64-bit variables, outside of using the high resolution timer for example. I'd misread Perkel's question to be about building an x64 executable for Win7 and was trying to advise on some gotchas when switching between 32 and 64 bit builds.

C# is a good, clean language to learn.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
Same. I found mine in my professor's library and it was from ca 1986 too. Should actually see that I get my own second hand copy because I have read it over 10 years ago.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,857
Fucking holidays and now i am sick.
did a bit of coding in free time and I run into a problem.

For example if i create from class few different objects and i add them to list, how can i for example check that list for specific class variable in that list ? I mean normally i would state for example var1 = Class(), var2 = Class() add that to listvar = [] and then later i would be able to use varx.name without using for loop but in code below each object in women list doesn't have variable beside hex code which is randomly generated upon creation of woman.

I mean for example :

Code:
count = 1
            while count == 1:
                print
                print "write woman name or back to go to previous menu"
                woman_choice = raw_input()
                for woman in women:
                    if woman.name == woman_choice:
                        print
                        print woman.disp()

                if woman_choice == "back":
                    count = 0

Because women is list with objects that have no defined name which i can use to call x.name i can't use for example if keyword as i don't know nor i can compare items in list to woman_choice

Above is workaround it works but it isn't how i think it should go.
Also i did some basic looping for UI. Hell yeah i can now make basic UI.
Also u did some I/O for exel and some basic GUI creation with python.

Morale + 2
as i wrote below mostly without any errors and as soon as i did any error i already knew what was going on.

said program :

WOMANIZER


full code below:

Code:
import random

# LISTS AND DICTS

colors = ['red', 'green', 'blue', 'black', 'white', 'yellow', 'purple', 'pink', 'brown', 'orange']
under_materials = ['satin', 'lace', 'material']
under_panty_types = ['thong', 'string', 'briefs', 'plain']
under_bra_types = ['push up', 'build in', 'sport', 'covertibile', 'demi', 'front closure', 'full support']
over_materials = ['denim', 'material', 'leather', 'corduroy', 'satin', 'silk']
over_low_type = ['pants', 'skirt', 'miniskirt',
                 'business type short skirt', 'school skirt', 'high cut skirt',
                 'low waist skirt', 'low waist pants']
over_high_types = ['blazer', 'shirt', 'low cut shirt', 'formal shirt', 'jersey']
boots_types = ['high heels', 'high boots', 'heels', 'slippers', 'running shoes']
body_hair_type = ['straight', 'curly', 'wave']
body_hair_size = ['long', 'short', 'very short', 'neck length']
body_hair_color = ['blonde', 'brown', 'black', 'grey']
body_skin_color = ['black', 'middle-eastern', 'white', 'asian']
body_bust_size = ['A', 'AA', 'B', 'BB', 'C', 'CC', 'D', 'DD']
body_state = ['obese', 'thin', 'anorexic', 'plain', 'petite', 'muscular', 'amazon-like', 'very fat']
clothing = ['OG', 'UG', 'B']
names = ['Alicia', 'Scarlet', 'Julia', 'Anastasia', 'Jennifer', 'Michael', 'Wendy', 'Volorun']
surnames = ['Hernandez', 'Rogozin', 'Wen', 'Catena', 'Goodwood', 'Istakason', 'Lista', 'Moon', 'Sunberry']
options = ["restart", "check woman", "quit"]
mainloop = 1
loop1 = 1
loop2 = 0
women = []

# CLASSES
class Woman(object):
    def __init__(self):
        self.name = random.choice(names) + ' ' + random.choice(surnames)
        self.age = random.randint(18, 45)
        self.skin = random.choice(body_skin_color)
        self.bust = random.choice(body_bust_size)
        self.hair_color = random.choice(body_hair_color)
        self.hair_type = random.choice(body_hair_type)
        self.hair_size = random.choice(body_hair_size)
        self.body_state = random.choice(body_state)
        self.inventory = []
        for x in clothing:   # clothing creation script
            if x == "OG":
                material = random.choice(over_materials)
                top = random.choice(colors) + " " + material + " " + random.choice(over_high_types)
                bottom = random.choice(colors) + " " + material + " " + random.choice(over_low_type)
                self.inventory.append(top)
                self.inventory.append(bottom)
            elif x == "UG":
                material = random.choice(under_materials)
                color = random.choice(colors)
                top = color + " " + material + " " + random.choice(under_bra_types) + " bra"
                bottom = color + " " + material + " " + random.choice(under_panty_types) + " panty"
                self.inventory.append(top)
                self.inventory.append(bottom)
            elif x == "B":
                boots = random.choice(colors) + " " + random.choice(over_materials) + " " + random.choice(boots_types)
                self.inventory.append(boots)
            else:
                pass

    def disp(self): # description function
        print
        print "=============================="
        print "NAME :   ", self.name
        print "AGE  :   ", self.age
        print "RACE :   ", self.skin
        print "=============================="
        print
        print "She has %s %s %s hair. Her bust size is %s" % (self.hair_size, self.hair_color, self.hair_type, self.bust)
        print "She is %s" % self.body_state
        print "She wears:"
        for x in self.inventory:
            print "   ", x
        print
        print "=============================="
        print

# MAIN CODE

while mainloop == 1:  # MAIN LOOP
    while loop1 == 1: # WOMAN GENERATOR LOOP
        print
        choice = raw_input("Do you want to create new woman (y/n) ?")
        if choice == "y":
            woman1 = Woman()
            women.append(woman1)
            print woman1.disp()
            print "Amount of women generated :", len(women)
            pass
        elif choice == "n":
            loop2 = 1
            loop1 = 0
        else:
            print "Wrong answer !"
            pass

    while loop2 == 1: # CHECK CREATED WOMAN UI LOOP
        print
        print "What do you want to do ? "
        print "Amount of women generated :", len(women)
        print "Available options:"
        print "=================="
        for option in options:
            print "   ", option
        print "=================="
        choice = raw_input("")
        if choice == "restart":
            women = []
            loop1 = 1
            loop2 = 0
        elif choice == "check woman":
            print
            print "=============="
            for woman in women:
                print woman.name
            print "=============="
            print
            print "Which woman you want to check ? "
            count = 1
            while count == 1:
                print
                print "write woman name or back to go to previous menu"
                woman_choice = raw_input()
                for woman in women:
                    if woman.name == woman_choice:
                        print
                        print woman.disp()

                if woman_choice == "back":
                    count = 0

        elif choice == "quit":
            loop1 = 0
            loop2 = 0
            mainloop = 0
        else:
            print
            print "Wrong answer, try again !"
            print

# REST OF CODE

print
print "=============================="
print "Thank you for using womanizer"
print "=============================="
print

raw_input()
 

Niektory

one of some
Patron
Joined
Mar 15, 2005
Messages
808
Location
the great potato in the sky
For example if i create from class few different objects and i add them to list, how can i for example check that list for specific class variable in that list ? I mean normally i would state for example var1 = Class(), var2 = Class() add that to listvar = [] and then later i would be able to use varx.name without using for loop but in code below each object in women list doesn't have variable beside hex code which is randomly generated upon creation of woman.

I mean for example :

Code:
count = 1
            while count == 1:
                print
                print "write woman name or back to go to previous menu"
                woman_choice = raw_input()
                for woman in women:
                    if woman.name == woman_choice:
                        print
                        print woman.disp()

                if woman_choice == "back":
                    count = 0

Because women is list with objects that have no defined name which i can use to call x.name i can't use for example if keyword as i don't know nor i can compare items in list to woman_choice

Above is workaround it works but it isn't how i think it should go.
I don't think there's any better way if you use a list to store them. If you need a fast lookup by name without going through all objects you need a different data structure. You could use a dictionary of lists for example. That would complicate things a bit though.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
Some stuff is better done with a relational database
SELECT * FROM *table* WHERE *variable* = *value*
otherwise write a function SelectBy(value) that returns a list and fills it in a loop.
you can also do some tricks with reflection but that would be a bit too much on your level
the key in a dictionary is usually a unique identifier (GUID) or a plain integer.
I advise from using eg a Name property as key because the key must be unique.
 

Burning Bridges

Enviado de meu SM-G3502T usando Tapatalk
Joined
Apr 21, 2006
Messages
27,562
Location
Tampon Bay
class ItemWithKey
{
protected string guid;
public string Guid
get
{
return guid;
}
//constructor:
public itemWithKey()
{
guid=new Guid().ToString();
}
}

every class that derives from this class then has basic Guid functionality
then whenever you add it into a dictionary, you can always use Guid as Key, and use polymorphism to retrieve it without even knowing the exact class
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,857
Ok i am still sick but i think i am ready for GOAL 3. Though i think for GOAL3 i should make most of my python experience for now. GOAL4 will be changing languge (synatax and stuff).

So without further additions :

==============
GOAL 3 - SHORT RPG - "THE GLOW"
==============


------------ Design: ----------------

Make an RPG in which you create your player and your goal is to earn enough money for supplies to leave area you are in (which contain several different places and events).

------------ Details: ---------------
  • Player will have randomly generated basic stats in range 1-5. To keep game simple stats will be precision, endurance and strength.
  • Combat will be simple and will contain melee weapons and range weapons as means to differentiate between weapons instead of them being actually melee and ranged. For example melee weapons will have formula that gives them low bonus to hit chance due to precision but big bonus to damage due to strength where in guns case it is reversed as precision will give big bonus to chance to hit where strength will have minor bonus to chance to hit but damage won't scale with either of those stats.
  • Player will start at random location (which will be "safe place") from which he will be able choose destination. Destinations will be randomly generated places. Those places will either be safe or contain event. Events will be mostly combat situations but can have safe scenarios.
  • In events player will be able to gather money for his goal either by looting corpses or checking place for valuables which can be sold later at shop.
  • Player will be able to buy and sell things at vendor and vendor will have randomly generated list of things he have.
 

Perkel

Arcane
Joined
Mar 28, 2014
Messages
15,857
Things going smoothly for now.

Created main menu and character creation menu
 

Norfleet

Moderator
Joined
Jun 3, 2005
Messages
12,250
rarely needed: float, short, byte, long
It is generally not purposeful to use short or byte, since once compiled, they will be represented by a single integer anyway. Unless you're doing something wonky with bitwise operations, there's no real reason to use these anymore. I am not sure if long is even distinct from int anymore, and if you really want something bigger, it's probably best to specify exactly what you want.
 

desocupado

Magister
Joined
Nov 17, 2008
Messages
1,802
I'll hijack this thread again for a bit.

So, I'm working on some stuff for uni, and I needed a 2d array, to simulate a matrix. After I got a stack overflow, I went to learn about the stack and the heap. Since my matrix is big, I needed to declare it using the new operator (I'm using C++ btw), but I discover you can't declare a 2d array using new.

So I went to search around on the net, and there's loads of convoluted solutions and stuffies, but one dude suggests:

Use the keyword auto:
auto array_of_something = new something[x][y];

And it works! It seems it only works on C++11 forward, but VS2010 ain't complaining about it, so :shrugs:

Anyway, my question is, what the fuck does the auto do in this case? Because I was JUST today reading about that stuff, and the C++ primer (which is probably C++03 compliant, since it's from 2005) says auto was a keyword to tell the compiler a variable had block scope, which they do by default and it was not actually needed. I read the C++11 improvements, and there's no mention of 2d arrays working with auto now.

So, why does this work?

EDIT: And how do I call delete[] on it?

EDIT2: How do I check the size of an object made from a class I made? And how do I check the size of the stack so I have an idea if I'm close to filling it up? Also, does the stack change from machine to machine, or if I compile for a different OS?
 
Last edited:

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