Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 431 432 [433] 434 435 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 909850 times)

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6480 on: October 24, 2014, 06:07:40 pm »

Half the time it works like you think it should, the rest of the time it explodes and wipes half a planet from existance.
That's better than my usual success rate, so I'm seeing this as an improvement.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Johuotar

  • Bay Watcher
    • View Profile
    • Some game projects
Re: if self.isCoder(): post() #Programming Thread
« Reply #6481 on: October 26, 2014, 03:34:59 pm »

Hi all. I'm trying to spawn some people to my game view. I have array that should contain the references to the actor class but I cannot actually put object into the array, so all the values are null. Currently I have error messages about the objects I'm trying to put into the array. I'm kind of stumped here. Part of the problem is I don't know any c++ and I'm using tutorial in c++ so translating it to c# is difficult. Please help.


code
Spoiler (click to show/hide)


errors
Spoiler (click to show/hide)

github link with all the code
https://github.com/Johuotar/Tower-Adventure

tutorial I'm using (article 8 )
http://www.kathekonta.com/rlguide/article8.html
Logged
[img height=x width=y]http://LINK TO IMAGE HERE[/img]
The Toad hops in mysterious ways.
This pure mountain spring water is indispensable. Literally. I'm out of paper cups.

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6482 on: October 26, 2014, 03:59:42 pm »

That tutorial should be thrown into the bowels of hell so that it may burn for an eternity and have its taint removed from this world.

EDIT:
The author is unaware of the existence of vectors and list.
The author is unaware of the existence of enums.
The author is concerned about the encapsulation of a boolean, while happily suggesting the use of an array of naked pointers.
The author keeps using this-> inside methods. (this one is just a nitpick)

Quote
As for the last criteria - Will This Make Me Want to Give Up Later On? - remember from previous articles, the number one challenge of programming is managing complexity..
Apparently the number one challenge is actually knowing the goddamn language features.
« Last Edit: October 26, 2014, 04:27:27 pm by cerapa »
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6483 on: October 26, 2014, 09:29:14 pm »

Also, saying C/C++ then blatantly using classes.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6484 on: October 26, 2014, 11:26:40 pm »

Heh, I've noticed that a lot of people have been cracking down on saying "C/C++" lately, especially at StackOverflow.  They've got a point too: the languages are almost nothing alike anymore.  I can't even decipher C++11 code half of the time, so I've all but given up on keeping up with the language in favor of writing C code if I absolutely must code in a compiled language, or older style C++ if I think I need OOP.  That basically amounts to manual memory management rather than smart pointers, STL containers and strings and very, very rare usage of templates.  I really should learn smart pointers...

Anyway, I'm not very experienced with C# as I've only fooled around with it a time or two, but I think your function should look closer to this:

Code: [Select]
        public bool AddActorToList(Actor p_cNewActor)
        {
            // Run through the list looking for an empty slot
            int i = 0;
            for (i = 0; i < GlobalVar.MAX_ACTORS; i++)
            {
                // Is this empty?
                if (actorlist.p_cActorList[i] == null)
                {
                    // If so, use it!
                    actorlist.p_cActorList[i] = p_cNewActor;
                    // Finished! Report success
                    return true;
                }
            }
            // Couldn't find a free slot. Report failure.
            return false;
        }

Your function's prototype was using [] notation, which means it was expecting an array of actors, but you wanted to only pass one to it.  I also fixed up actorlist.p_cActorList to use [] notation inside your loop, since it was trying to reassign the entire array instead of just one element of it.  Hopefully my brief scanning of it didn't completely miss the point of the function.
Logged
Through pain, I find wisdom.

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #6485 on: October 27, 2014, 12:45:52 am »

Spoiler (click to show/hide)

Welp. This is what the book calls for. And suddenly with the introduction of scripting the amount of stuff I have to type is multiplied by 10 million. *sighs and gets to work*
Logged

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6486 on: October 28, 2014, 02:52:04 am »

Hint to anyone doing anything:

When iterating through a list/map/vector with a for loop, do not change the list/map/vector from inside the loop. Half the time it works like you think it should, the rest of the time it explodes and wipes half a planet from existance.

It is a lesson I have had to learn many times, but somehow I always forget.

I hesitate to post in this thread because I'm just a Python baby, but have you tried iterating through the list backwards?  That's worked for me when I've needed to remove entries from a list while iterating through it.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6487 on: October 28, 2014, 03:58:00 am »

Code: [Select]
list = stuff
newList = empty list
for thing in list:
    do_stuff()
    append thing to newList
list = newList
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6488 on: October 28, 2014, 06:34:09 am »

But what if that list has 10 million elements? D:
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6489 on: October 28, 2014, 08:07:38 am »

Parallelize it!
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6490 on: October 28, 2014, 09:37:55 pm »

Make smaller lists? Get more RAM?
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Sergius

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6491 on: October 29, 2014, 12:00:02 am »

Don't add/remove items to the list until you're finished looping. Defer it for after.
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6492 on: October 29, 2014, 12:26:53 am »

How would that work?
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6493 on: October 29, 2014, 12:53:42 am »

Find a way to track all the elements you need to remove, then after you get a list of elements to remove, do that.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Johuotar

  • Bay Watcher
    • View Profile
    • Some game projects
Re: if self.isCoder(): post() #Programming Thread
« Reply #6494 on: October 29, 2014, 03:51:39 am »

-snip-
Thanks Telgin, I've made more progress now that got fixed. The code isn't perfect yet but you were of much help.
Logged
[img height=x width=y]http://LINK TO IMAGE HERE[/img]
The Toad hops in mysterious ways.
This pure mountain spring water is indispensable. Literally. I'm out of paper cups.
Pages: 1 ... 431 432 [433] 434 435 ... 796