We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,687 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Array Alternatives?

Hi there,
I am coding for an engine based on C that supports everything apart from arrays. Now what I want to do is this:

int Populate(int Amount, string TagArray[], float xLoc[], float yLoc[], float zLoc[], float Orient[])
{
	int AutoInc = 0;
	
	while(AutoInc < Amount)
	{
              int a = AutoInc;              

		CreateObject(OBJECT_TYPE_CREATURE, TagArray[AutoInc], Location(Vector(xLoc[AutoInc], yLoc[AutoInc], zLoc[AutoInc]), Orient[AutoInc]);

		AssignCommand(TagArray[AutoInc],ActionRandomWalk());

		AutoInc++;
	}
       return 0;
}

I found out after writing this that the engine doesn't support arrays. Is there any way that I can do this without arrays?

I did have a look at structs but couldn't get my head around using them like this.

Thanks in advance.

TB12

4
Contributors
12
Replies
4 Days
Discussion Span
2 Years Ago
Last Updated
13
Views
TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Are you sure this is C? I ask because you have a type string.

gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0

I m used to using C++ so there is probably something wrong in there. Whats the C alternative?

TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

C doesn't have objects. The closest thing is a C-string which is an array of characters terminated by '\0'.

char str1[] = "this is a string";/*compiler adds the '\0'*/
char *str2 = "this is another string";/* but its non mutable and the compiler adds the '\0'"*/
char str3[] = {'s','t','r','i','n','g','\0'};/*another string*/
char str4[]  = {'n','o','n'','-','s','t','r','i','n','g'};/*not a string no '\0'*/
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0

Unfortunately I can't use arrays. Is there any other way of doing what I want or should I just give it up?

TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You'll have to elaborate why the engine doesn't support arrays and what exactly it does support...We can't grab a crystal ball and gaze into your game engine.

gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0

Here is some info although it pretty much supports most things except arrays.

does not have many functions from the C family, excluding logical and binary / ternary operators and some mathematical functions

It also supports the data type of string.

allows structs, but not objects.

The following common data types are available

* integer (int)
* float
* string
* struct

Once again any help is appreciated.

TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

It also supports the data type of string.

Then its not C. Why don't you write this in C++?

gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0

Because I was told the engine is based on C. It is NWScript and has lots of its own variable types.

TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

>>allows structs, but not objects.
string is an object, or more technically called c++ class.

Ancient Dragon
Achieved Level 70
Team Colleague
32,109 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,575
Skill Endorsements: 68

Here's more info

http://en.wikipedia.org/wiki/NWScript

http://nwn.wikia.com/wiki/NWScript

Im starting to doubt if this is possible.

TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Sorry. Dodgy tabs and computer reboot caused a double post.

TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You always can use list.
Your environment supports structures:

typdef struct {
NODEtype*Previous;
NODEtype *Next;
int Datatype;
unsigned long int DabaBlockSize;
void *DataBlock;
}NODEtype;


You an store any object in this node, and concatenate nodes to from a list.
by marking the first and last elements, you can traverse the list ack and forth using pointer arithmetics. Pass the list to any funciton by passing a pointer to any element of the list.Preferable, use the first element... but it is not a must.

Layosh
Newbie Poster
1 post since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1818 seconds using 2.71MB