Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Array Difficulties

Author
Message
MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 15th Jul 2010 17:39
Alright. So I'm having difficulties setting values to my array. I'm basically using an array to store what goes where in the level, then another function which goes through which creates all the sprites, positions them, etc. But first I'm having issues with making the syntax correct. So here's the original code I had:



I followed the syntax which was outlined here for arrays. But Visual Studio 2008 Express doesn't seem to like that, and it compiles with 42 errors... Oh joy.

So then I went through fixing all the errors... And the compiler seems to agree with the below..Almost.



It still has one error in it;



Which I can't seem to fix, which is why I'm posting. Line 8 is the very first line that I've posted in the code. So can someone explain to me how to set values to the array, using this style?
Greg_C
14
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 15th Jul 2010 18:01
It because of the semicolon right here:

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 15th Jul 2010 18:22


The link you gave is correct, you have just overlooked a couple of things, the array needs a type(int) and you missed out some comma's.

MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 15th Jul 2010 18:30
Ah, should have mentioned that above, I declared the int previously. I'll check out the commas, now!
MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 15th Jul 2010 18:33
Seems I can't edit, so sorry for the double post.



When I compile your version, I receive all these errors - which is why I had ; stuck throughout the second version of the code.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 15th Jul 2010 18:40
I don't get those errors, did you try it exactly how I posted it(declaring the type etc)?
Post all your code and we may find the issue.

MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 15th Jul 2010 20:16


Since I'm using a global variable to hold the level data, I can't declare it again. I tried using "extern int level[13][50] = ...." and it just gave me new errors. If you want the solution, I can attach it.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 15th Jul 2010 21:12 Edited at: 15th Jul 2010 21:14
I think you can only initialise an array like that upon creation.
There may be lots of different solutions using dynamic memory allocation and pointers which may be faster but here is something simple which should work.

Create a function to set the array:


You can then have your global array:


When you want to set its values, create a new array:


Then use your function to set the values of the global array to that of the newly created array:


MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 15th Jul 2010 21:26
Ah, I see. I'll try that.
MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 16th Jul 2010 00:35
Alright. So here's the thing. I was thinking about it for quite some time, and I realized that making it a global variable is just a waste of memory. I'm just going to use one variable which then is used to determine the level, and it creates it based off that. But how exactly do I pass the array correctly?

Here's what I've got, for the two functions:



And when compiled, I get the error
, so I'm obviously doing it wrong. So do I?
Bran flakes91093
15
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 16th Jul 2010 03:17
Make sure you change the prototype also:

void BuildLevel(void); -> void BuildLevel(int level[13][50]);

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 16th Jul 2010 03:22
Great, thanks.

Login to post a reply

Server time is: 2024-07-04 09:31:44
Your offset time is: 2024-07-04 09:31:44