1,105,352 Community Members

Array Alternatives?

Member Avatar
TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
gerard4143
Nearly a Posting Maven
2,385 posts since Jan 2008
Reputation Points: 371 [?]
Q&As Helped to Solve: 409 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
gerard4143
Nearly a Posting Maven
2,385 posts since Jan 2008
Reputation Points: 371 [?]
Q&As Helped to Solve: 409 [?]
Skill Endorsements: 0 [?]
 
1
 

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'*/
Member Avatar
TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
gerard4143
Nearly a Posting Maven
2,385 posts since Jan 2008
Reputation Points: 371 [?]
Q&As Helped to Solve: 409 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
gerard4143
Nearly a Posting Maven
2,385 posts since Jan 2008
Reputation Points: 371 [?]
Q&As Helped to Solve: 409 [?]
Skill Endorsements: 0 [?]
 
0
 

It also supports the data type of string.

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

Member Avatar
TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Ancient Dragon
Achieved Level 70
27,577 posts since Aug 2005
Reputation Points: 5,231 [?]
Q&As Helped to Solve: 3,028 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

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

Member Avatar
TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Here's more info

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

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

Im starting to doubt if this is possible.

Member Avatar
TimBob12
Newbie Poster
16 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Layosh
Newbie Poster
1 post since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: