Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 42 43 [44] 45 46 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100893 times)

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #645 on: June 21, 2012, 04:40:05 am »

Thank you. Once I finish reading my textbook about C# for starters I will get one for XNA usage :).
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #646 on: June 21, 2012, 12:14:33 pm »

Then, finally, it would run.

Did the canvas actually get shaded for you? I keep getting the error 'can't convert undefined to object'.

EDIT: Oh, wait. The array was the problem. Nevermind!
« Last Edit: June 21, 2012, 03:07:16 pm by Araph »
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #647 on: June 21, 2012, 12:18:31 pm »

No shader, no problem?
Logged

thobal

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #648 on: June 23, 2012, 10:27:33 am »

c++ question

I've been using BDA(big dumb arrays) to hold a lot of my data while avoiding figuring out dynamic memory. Now, I started experimenting with dynamic memory about the same time this problem came up, so it threw me off for a bit. But I've isolated it a bit better now so I've decided to pose the question.

Code: [Select]

const maxPopulation = 20000;

class Human
{

int foo[maxPopulation];
int foo2[maxPopulation];

ect...

};


The problem has begun to arise that during program start up, the program will crash.  I know it has to do with the size of the arrays and not the code itself for two reasons. One) a printf(); on the first line of main(); never executes and Two) more obviously, when I decrease the value of maxPopulation enough, the problem goes away.

Now I'm a total, fly by night, learn as I go, hobby this sucker out when I'm not studying for exams style amateur. So I've been stick parts of the humans into different classes on the principle that they'll still be associated merely by "foo" in this example "names.array[foo]" is the name of "guy.array[foo]"

But is there any(incredably simple)way around this or am I stuck making more and more classes to keep some single class memory limit from being hit(or bothering to learn more about memory management)?
« Last Edit: June 23, 2012, 10:36:36 am by thobal »
Logged
Signature goes here.

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Help Thread (For Dummies)
« Reply #649 on: June 23, 2012, 11:01:27 am »

A random guess: You're creating an instance of it on the stack, which has limited space, causing it to overflow. Making it global, static, or creating it with new would fix that, if that is the issue.

Could be something else, though.

Edit:
I should probably clarify what I mean: I'm guessing that, from a similar issue I had long ago, and from some of the details, that you have a local variable of that class, probably declared in main(). Since it is a local variable, it will be placed on the stack, rather than the heap (which is generally used for static variables, global variables, and anything created with new or malloc (or similar things) while the program runs. There is usually a relatively small amount of memory set aside for the stack, and, these days, often gigabytes of space for the heap.
« Last Edit: June 23, 2012, 11:05:20 am by qwertyuiopas »
Logged
Eh?
Eh!

thobal

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #650 on: June 23, 2012, 11:22:18 am »

Haha! It works! A thousand thank yous, I can continue to read as little as possible as I code.
Logged
Signature goes here.

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #651 on: June 23, 2012, 01:12:59 pm »

So, I've run into another problem with JavaScript.
Code: [Select]
function  actionMenuLeave () {
    var xOne = 1;
    var xTwoMove = 0;
    var xTwo = 1;
    var xThreeMove = 0;
    var xThree = 1;
    var xFourMove = 0;
    var xFour = 1;
   
    var i = 0;
   
    while ( i =0 ) {
        panelContext.clearRect (0,0,400,100);
       
        if (xOne > 0) { xOne = xOne - .05; }
       
        if (xOne = 0.5) { xTwoMove = 1;}
        if (xTwoMove = 1) {xTwo = xTwo - .05;}
       
        if (xTwo = 0.5) { xThreeMove = 1;}
        if (xThreeMove = 1) {xThree = xThree - .05;}
       
        if (xThree = 0.5) { xFourMove = 1;}
        if (xFourMove = 1) {xFour = xFour - .05;}
       
        if (xFour = 0) {i = 1;}
       
        panelContext.fillStyle = "#FFAAAA";
        panelContext.fillRect (0,0,100,(100*xOne));
        panelContext.fillStyle = "#A89058";
        panelContext.fillRect (100,0,200,(100*xTwo));
        panelContext.fillStyle = "#AAAAFF";
        panelContext.fillRect (200,0,300,(100*xThree));
        panelContext.fillStyle = "#EEEEEE";
        panelContext.fillRect (300,0,400,(100*xFour));
       }
    }
What this is supposed to do when it's called is make four menu boxes flatten down to nothing so that new boxes can appear in their place. The height of the boxes are multiplied by a number between one and zero to produce a shrinking rectangle instead of a square, but it doesn't work properly. I know that the function is being called in the right place, and I think that it could be that the function is performed really fast and then the menu gets drawn over again by some other function. I'm just posting this to ask if anybody sees another stupid mistake on my part in there.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #652 on: June 23, 2012, 02:49:47 pm »

Yeah it doesn't work that way, your code will run inbetween screen-draws. You'll need to use setTimeout somewhere, or use a similar function by a framework.

If you want that in more detail I can give it to you, but right now I'm assuming you know a bit about JS :)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #653 on: June 23, 2012, 03:38:32 pm »

You could make it a closure that decreases the proportionality factor and redraws the screen every time it's called and then call that in the main loop.
Logged

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #654 on: June 23, 2012, 06:39:06 pm »

...right now I'm assuming you know a bit about JS :)
Oh, I wish.

You could make it a closure that decreases the proportionality factor and redraws the screen every time it's called and then call that in the main loop.
I thought the computer would redraw the screen when the fillRect command was given, but I guess not.

Code: [Select]
function  actionMenuLeave () {
    var i = 0;
   
    var xOne = 1;
    var xTwoMove = 0;
    var xTwo = 1;
    var xThreeMove = 0;
    var xThree = 1;
    var xFourMove = 0;
    var xFour = 1;

    while ( i =0 ) {
        if (xOne > 0) { xOne = xOne - .05; }
       
        if (xOne = 0.5) { xTwoMove = 1;}
        if (xTwoMove = 1) {xTwo = xTwo - .05;}
       
        if (xTwo = 0.5) { xThreeMove = 1;}
        if (xThreeMove = 1) {xThree = xThree - .05;}
       
        if (xThree = 0.5) { xFourMove = 1;}
        if (xFourMove = 1) {xFour = xFour - .05;}
       
        if (xFour = 0) {i = 1;}
       
        setInterval ("panelTransitionTimer(xOne, xTwo, xThree, xFour)", 5);
       }
    }

function panelTransitionTimer (xOne, xTwo, xThree, xFour) {
        panelContext.clearRect (0,0,400,100);
       
        if (menu == 0) { //Main
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (0,0,100,(100*xOne));
            panelContext.fillStyle = "#A89058";
            panelContext.fillRect (100,0,200,(100*xTwo));
            panelContext.fillStyle = "#AAAAFF";
            panelContext.fillRect (200,0,300,(100*xThree));
            panelContext.fillStyle = "#EEEEEE";
            panelContext.fillRect (300,0,400,(100*xFour));
            }
       
        if (menu == 1) { //Attack
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (0,0,100,(100*xOne));
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (100,0,200,(100*xTwo));
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (200,0,300,(100*xThree));
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (300,0,400,(100*xFour));
            }
}

I think this is how I'm supposed to use the setTimeout command. Key word being 'think', because I know at least one thing isn't working.

And thanks for all the help! I really appreciate it.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #655 on: June 24, 2012, 02:44:54 am »

Try it like this?

Code: [Select]
function actionMenuLeave () {   
    var xOne = 1;
    var xTwo = 1;
    var xThree = 1;
    var xFour = 1;
    function doTransit(xOne,xTwo,xThree,xFour);
}

function panelTransition (xOne, xTwo, xThree, xFour) {
        panelContext.clearRect (0,0,400,100);
       
        if (menu == 0) { //Main  <-- Is menu a global?
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (0,0,100,(100*xOne));
            panelContext.fillStyle = "#A89058";
            panelContext.fillRect (100,0,200,(100*xTwo));
            panelContext.fillStyle = "#AAAAFF";
            panelContext.fillRect (200,0,300,(100*xThree));
            panelContext.fillStyle = "#EEEEEE";
            panelContext.fillRect (300,0,400,(100*xFour));
    }
}
       
        if (menu == 1) { //Attack
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (0,0,100,(100*xOne));
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (100,0,200,(100*xTwo));
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (200,0,300,(100*xThree));
            panelContext.fillStyle = "#FFAAAA";
            panelContext.fillRect (300,0,400,(100*xFour));
            }
}

function doTransit(xOne,xTwo,xThree,xFour){
        var xTwoMove = 0;
        var xThreeMove = 0;
        var xFourMove = 0;
        var i = 0;
        if (xOne > 0) { xOne = xOne - .05; }
       
        if (xOne = 0.5) { xTwoMove = 1;}
        if (xTwoMove = 1) {xTwo = xTwo - .05;}
       
        if (xTwo = 0.5) { xThreeMove = 1;}
        if (xThreeMove = 1) {xThree = xThree - .05;}
       
        if (xThree = 0.5) { xFourMove = 1;}
        if (xFourMove = 1) {xFour = xFour - .05;}
       
        if (xFour = 0) {i = 1;}
        panelTransition (xOne, xTwo, xThree, xFour) ;
        if(i == 0){
            setInterval ("doTransit(xOne, xTwo, xThree, xFour)", 5);
        }
}

Quote
I think this is how I'm supposed to use the setTimeout command. Key word being 'think', because I know at least one thing isn't working.
Nope. What it does is set a function call on a separate list somewhere, so it gets called in the future. Right now what you have is x of those functioncalls, each to be called at the same time in the future. It could work if you increased the timer each time its gets called, though, although I (obviously) prefer it my way, as it can be stopped easier if it's interrupted.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #656 on: June 24, 2012, 10:49:55 am »

So I am back. Before I move on to more advanced coding learning, I want some good programmer's advice on my very basic endavours. Using a tutorial which shows how to make new classes as a reference, I've made a complex number class (probably one of the easiest tasks). So if you have 3-5 minutes of your time, I would like some critics on my coding style (which I haven't developed yet). I want to learn to do stuff "correctly", so I would be able to work with other people and my code would be readable.

Just basic advices about indentations, variable naming et cetera. Thank you in advance.

Main.cs : http://pastebin.com/jNsPWBds
Complexdef.cs: http://pastebin.com/DPPrKNBL
« Last Edit: June 24, 2012, 10:53:12 am by Deon »
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #657 on: June 24, 2012, 01:17:44 pm »

Alright, here I really need your help.

I seem to misunderstand how to use classes properly.

Here I try to assign special variables to array elements, and get errors.

The code is:
main.cs     : http://pastebin.com/yDzQAuP6
itemdef.cs : http://pastebin.com/EYRdihim

The three errors are: "melee" is a type but is used as a variable, or something like that.

Obviously it does not like the mweapons[0] = melee("Copper sword", 1, 6, 50); and the like.

However I have overloaded "melee()" with "melee(string, int, int, int)", what did I do wrong?
« Last Edit: June 24, 2012, 01:54:49 pm by Deon »
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Soadreqm

  • Bay Watcher
  • I'm okay with this. I'm okay with a lot of things.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #658 on: June 24, 2012, 01:47:07 pm »

One problem seems to be that you're trying to add things to a null array. You need something like
Code: [Select]
melee[] mweapons = melee[3];to actually create the array. Also, I can't remember how C# syntax works anymore, but in Java, you'd need some import declarations on top of main.cs to tell it that it's allowed to use resources from itemdef.cs.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #659 on: June 24, 2012, 01:52:01 pm »

Even if I make it a
Code: [Select]
melee[] mweapons = new melee[3];it still dislikes the usage of type instead of a variable, so I think there's a problem with my overloading of melee().
And no, if it didn't see the stuff from the other .cs files, it would tell that in the errors.
You don't have to be "using" stuff from other files, they are loaded automatically because they belong to the same project. C# does not use the "include" system. There's something much easier and it must be really stupid that I don't see it :D.
« Last Edit: June 24, 2012, 01:53:51 pm by Deon »
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository
Pages: 1 ... 42 43 [44] 45 46 ... 91