Ironworks Gaming Forum

Ironworks Gaming Forum (http://www.ironworksforum.com/forum/index.php)
-   General Discussion (http://www.ironworksforum.com/forum/forumdisplay.php?f=36)
-   -   Any Programmers out there? (http://www.ironworksforum.com/forum/showthread.php?t=96290)

Ilander 06-05-2006 03:43 PM

...So, I was getting my dork on, making an NPC battle simulator, when it occurred to me that the most efficient method for doing so was to build a nine dimensional array, representing a myriad of stats...problem is, I can't remember crap from my CS 115 class, other than the basics, and the MSDN library is a little on the technical side...so what I really need to know is the following:

1)What's the syntax for storing something to a single element of an array?
2)What's the syntax of a for loop?

I guess that's it for now...if you all know of where I could find that (I'd hate to buy a forty dollar book just for two little things like that!), you'd win my complete admiration and respect!

EDIT: OH, this is in C++ ...might need that!

[ 06-05-2006, 03:47 PM: Message edited by: Ilander ]

robertthebard 06-05-2006 04:53 PM

I used to know how to program in Basic, will that help???

dplax 06-05-2006 05:08 PM

To place an element into an array you should use:

</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">array [i][j]...[n]=datatoinput</pre>[/QUOTE]where the first [] represents the first dimension, the second the second, etc.


The syntax for a for loop is:

</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">for (commandToExecuteAtStart; exitCondition; commandToExecuteAtEachIteration){}</pre>[/QUOTE]and then you would put the instructions you want to execute inside the {}. Two examples would be:

</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">for (i=0; i&lt;n; i++)</pre>[/QUOTE], which does n iterations
</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">for ( ; ; )</pre>[/QUOTE], which is an infinite for loop.


Hope that helps.

Knightscape 06-05-2006 06:41 PM

Here's a C/C++ reference page and a tutorial on arrays.

http://www.onesmartclick.com/program...cplusplus.html

http://www.cplusplus.com/doc/tutorial/arrays.html

andrewas 06-06-2006 06:54 AM

A nine dimensional array? That sounds wrong. If your doing what I think your doing, you want a one dimensional array of data structures, where the struct contains everything you need to know about one NPC. If you know any STL, use a std::vector instead of an array, its more efficient, but if you dont know STL but do know how to use an array safely, go ahead with an array.

Ilander 06-06-2006 07:11 AM

...Have not seen data structures...that's the first topic in CS 215, which I intend to take next spring.

I was going to have a nine dimensional array that represented each stat of each character...an allegiance stat, unit number, HP, strike bonus, Attacks Per Round, damage dealt, initiative, and a stat that qualified the NPC as dead.

I didn't know how to make an array of varying types (it would be nice to have one that had boolean values as well as integers!)...so, my program is going to have lots of loops...lots and lots...and yeah, it seems my list is only eight long...I don't have my laptop up and running, otherwise I'd go ahead and write down exactly what they are.

...In my first post, I meant how to I store a value to an element in an array.

Say, I want the fifth element in an eight dimensional array to be four. How do I do that?

[ 06-06-2006, 07:30 AM: Message edited by: Ilander ]

Drakilor 06-06-2006 08:31 AM

I don't think the latest question suffice for an eight dimensional array.
</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">arra[a][b][c][d][e][f][g][h] = value
// Wich of these arrays do you want to change element 4 in?</pre>[/QUOTE]If you want to store data for n ammount of bots, a much easier way is to store a structure or an object described by a bot class in each element. You could get something like this:
</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">myBotArray[botIdentificator].Health = 100
myBotArray[botIdentificator].IsDead = false</pre>[/QUOTE]

Ilander 06-06-2006 04:15 PM

Looks worth looking up how to do, as it's exactly what I had wanted to do.

Thoran 06-06-2006 07:19 PM

I've been programming for a LONG time (22+ years)... and I don't recall everr using more than a 3d array, and I can probably count the number of those on one hand.

I think you need to think about your architecture some... something doesn't sound right to me.

[ 06-06-2006, 07:20 PM: Message edited by: Thoran ]

Bungleau 06-06-2006 07:57 PM

I'll agree with Thoran... rethink your design. A nine-dimension array violates quite a few basic concepts of database design. In fact, from a true database perspective, you'd have something like...

... a character record with a key and description
... a stats table keyed off the character and stat type and containing the stat value

You'd look up the character, then the stats. If you wanted, the stats record would just have columns for each stat so you could retrieve it once.


All times are GMT -4. The time now is 09:50 AM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved