Declaring arrays
Displaying 1-8 of 8 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
sndr

I just started using verge, read the tutorials and when I tried to test some stuff, I found the following problem:

int numbers[15]; //makes a list of 15 integers
string names[7]; //this one is a list of 7 strings
numbers[0] = 42; //this sets the first member of 'numbers' to 42.
numbers[14] = 3; //this sets the last member of 'numbers' to 3.

(this is straight copypaste from the manual)

when I try to run this code, I get this error:

system.vc(3): Expecting ",", but got "[" instead
(line 3 is the first line of the code I posted)

what is wrong with the code?

Posted on 2011-05-22 21:18:01 (last edited on 2011-05-22 21:18:47)

mcgrue

post the entire system.vc, please?

Posted on 2011-05-23 00:03:25

sndr

void autoexec() 
{
int numbers[15]; //makes a list of 15 integers
string names[7]; //this one is a list of 7 strings
numbers[0] = 42; //this sets the first member of 'numbers' to 42.
numbers[14] = 3; //this sets the last member of 'numbers' to 3.
while (!b3)
	{
		RectFill(0, 0, ImageWidth(screen), ImageHeight(screen), 0, screen);
				PrintCenter(ImageWidth(screen)/2, ImageHeight(screen)/2, screen, 0, string(numbers[0]));
		ShowPage();
	}
	Exit("Bye!");
}


there you go

Posted on 2011-05-23 10:51:54

Overkill

VC has a (lame) limitation that you can't declare arrays or structs as local variables. So you end up having to declare a ton of global arrays with hardcoded max sizes. Yeeeah, it's very ugly, and is a severe limitation of the VC compiler and interpreter.

Posted on 2011-05-23 16:13:25 (last edited on 2011-05-23 16:14:46)

sndr

and all variables are local by default?

how do I declare local/global vars? (the manual isn't very clear about this)


EDIT: problem solved. thanks guys.

Posted on 2011-05-23 16:21:47 (last edited on 2011-05-23 16:49:23)

mcgrue

overkill, could you clarify the docs to this effect in that location?

Posted on 2011-05-23 18:36:39

Overkill

Okay, updated the docs on arrays and structs a little:

http://verge-rpg.com/docs/the-verge-3-manual/arrays
http://verge-rpg.com/docs/the-verge-3-manual/structs

And the scoping stuff on the variables page was made a little more clear (actually saying how to declare a global vs local variable, instead of just saying what one is without much elaboration):
http://verge-rpg.com/docs/the-verge-3-manual/variables

Hopefully that helps!

Posted on 2011-05-23 20:37:53

Kildorf

Oh, VergeC, you so crazy.

Posted on 2011-05-29 00:38:41


Displaying 1-8 of 8 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.