These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

Out of Pod Experience

 
  • Topic is locked indefinitely.
 

Working with C++ (programming assistance requested)

Author
Alexa de'Crux
Brutor Tribe
Minmatar Republic
#1 - 2013-08-30 22:35:30 UTC
Some of you, who probably don't read this forum, already know that I'm teaching myself C++. My efforts, however, have hit a snag.

I've set up an array that holds 10 random values; I want to use those numbers in a function as seeds for my randomized levels, but I can't figure out how to tie the array in to the level generator.

I've attempted to use pointers, but I'm not sure they'll do what I want, and I don't know how the heck they work anyhow :)

Is there a kind soul out there that can shed a light on things for me? :)
Caleidascope
Republic Military School
Minmatar Republic
#2 - 2013-08-30 23:04:07 UTC
That sounds like regular C stuff, not even C++.

You can address the specific cell of the array. Let say you have declared an array called TestArray:
int TestArray[10]={3,4,7,9,8,etc};
So later when you need a value stored in specific cell of the array, you just call for that cell. Example:
TestArray[0] is the very first cell, it contains 3.
TestArray[1] contains 4.
TestArray[2] contains 7.
etc.

Life is short and dinner time is chancy

Eat dessert first!

Alexa de'Crux
Brutor Tribe
Minmatar Republic
#3 - 2013-08-30 23:50:13 UTC
Caleidascope wrote:
That sounds like regular C stuff, not even C++.

You can address the specific cell of the array. Let say you have declared an array called TestArray:
int TestArray[10]={3,4,7,9,8,etc};
So later when you need a value stored in specific cell of the array, you just call for that cell. Example:
TestArray[0] is the very first cell, it contains 3.
TestArray[1] contains 4.
TestArray[2] contains 7.
etc.


Okay! So, I'd just put TestArray[0] in the CreateRoom function?
Pepper Swift
Perkone
Caldari State
#4 - 2013-08-30 23:57:45 UTC
Alexa de'Crux wrote:
Caleidascope wrote:
That sounds like regular C stuff, not even C++.

You can address the specific cell of the array. Let say you have declared an array called TestArray:
int TestArray[10]={3,4,7,9,8,etc};
So later when you need a value stored in specific cell of the array, you just call for that cell. Example:
TestArray[0] is the very first cell, it contains 3.
TestArray[1] contains 4.
TestArray[2] contains 7.
etc.


Okay! So, I'd just put TestArray[0] in the CreateRoom function?



if you put testArray[0] it will only pick the value of the FIRST index.. in the example above.. it will pick 3..

are you trying to use all the values in the array? then you will need to use something else to pick the values in the array.. The most common is a loop.

From your first description, it sounds like all you want is to use a random number generator.

i think a more elegant solution is to create a random number generator function, and whenever you need a random number generator, just call that function.. that way you can ignore dealing with array indexing in that specific part of the code.

What I need most.. is a day between Saturday and Sunday...

If life gives you melons, you might be dyslexic

Caleidascope
Republic Military School
Minmatar Republic
#5 - 2013-08-31 00:01:17 UTC
Alexa de'Crux wrote:
Caleidascope wrote:
That sounds like regular C stuff, not even C++.

You can address the specific cell of the array. Let say you have declared an array called TestArray:
int TestArray[10]={3,4,7,9,8,etc};
So later when you need a value stored in specific cell of the array, you just call for that cell. Example:
TestArray[0] is the very first cell, it contains 3.
TestArray[1] contains 4.
TestArray[2] contains 7.
etc.


Okay! So, I'd just put TestArray[0] in the CreateRoom function?

Then the CreatRoom function will use the value stored in the TestArray[0] cell.


Life is short and dinner time is chancy

Eat dessert first!

Alexa de'Crux
Brutor Tribe
Minmatar Republic
#6 - 2013-08-31 00:22:49 UTC
Pepper Swift wrote:
Alexa de'Crux wrote:
Caleidascope wrote:
That sounds like regular C stuff, not even C++.

You can address the specific cell of the array. Let say you have declared an array called TestArray:
int TestArray[10]={3,4,7,9,8,etc};
So later when you need a value stored in specific cell of the array, you just call for that cell. Example:
TestArray[0] is the very first cell, it contains 3.
TestArray[1] contains 4.
TestArray[2] contains 7.
etc.


Okay! So, I'd just put TestArray[0] in the CreateRoom function?



if you put testArray[0] it will only pick the value of the FIRST index.. in the example above.. it will pick 3..

are you trying to use all the values in the array? then you will need to use something else to pick the values in the array.. The most common is a loop.

From your first description, it sounds like all you want is to use a random number generator.

i think a more elegant solution is to create a random number generator function, and whenever you need a random number generator, just call that function.. that way you can ignore dealing with array indexing in that specific part of the code.


I've got the PRNG working. I'm just trying to store the level seeds when the game starts, so that I can create ten levels and go back and forth through the array.
Socks the Fox
Sebiestor Tribe
Minmatar Republic
#7 - 2013-08-31 22:12:26 UTC
Okay, let's say you have an array "seeds", and you want only the one room's seed to be passed to the room generator. Let's call this room index variable "x". To get the specific seed for room x, you'd use "seeds[x]" which gets the seed at position X. for all practical purposes you can treat that entire little phrase as a variable, meaning you can assign to "seeds[x]", do math with it, or pass it directly to a function that accepts a [whatever the array type is] like this: "GenerateRoom(seeds[x])".