array help
Displaying 1-9 of 9 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
chanman


int lineNum = 0;
string line[255];

while(blah) {
// some code
line[lineNum] = str;
// some more code
lineNum++;
}


is the line[lineNum] = str; valid?

Posted on 2006-01-19 19:18:58

RageCage

as long as str is a string, yes. Also, all arrays have to be declaired globally.

Posted on 2006-01-19 19:43:10

Overkill

Okay, You'll want to put in some boundary checking, to make sure line num never exceeds 255.


int lineNum = 0;
string line[255];

while(blah)
{
if (lineNum >= 255)
{
blah = 0; // If we risk going out of array bounds, exit the loop. Though, a better idea than this is to use for loops since they're better with arrays.
}
// some code
line[lineNum] = str;
// some more code
lineNum++;
}


I don't know what you're trying to do, but that might help you. If you're using the while() loop to set the line[] array maybe you could use a for() loop instead.

EDIT: line is reserved identifier. Since Line(int x, int y, int x2, int y2, int color, int dest). So use something else.

Posted on 2006-01-19 19:57:15

chanman

here is my function, it takes 2 arguements: font and string. It takes the string and splits it up so it doesnt run off the screen. Anyway, I'm getting a error on line 22 saying "exspected '(', but got ',' "

string textBoxLine[255];

void TextBox(int fontFace, string myStr) {
int lineNum;
int count;
int x;
string word;
string str1;
string strTemp;

lineNum = 0;
count = TokenCount(myStr, " ");
x = 0;

int bounds = imageshell(0, 0, imageWidth(screen),
(FontHeight(fontFace) * 3) + imageHeight(5) +
imageHeight(5) + 6, screen);

int textBounds = imageShell(5, 5, imageWidth(bounds) - 10, (fontHeight(fontFace) * 3), bounds);

while(x < count && x < 255) {
word = GetToken(str, x);
strTemp = str1 + " " + word;
if(textWidth(strTemp) > imageWidth(textbounds) {
textBoxLine[lineNum] = str1;
}
else {
x++;
lineNum++;
}
}

rectFill(0, 0, imageWidth(bounds), imageHeight(bounds), rgb(0,0,200), bounds);

for(x = 0; x <= lineNum; x++) {
printString(0, (fontHeight(fontFace) * x), textBounds, fontFace, textBoxLine[x]);
}
}

Posted on 2006-01-19 20:25:30

Omni

<code>Line 22
word = GetToken(str, x);</code>
Oops! We forgot to mention.

"Str" is also a reserved identifier. See Str(int num). Which converts a number to a string.

Use something original, like "mystring". That should fix it fine.

Posted on 2006-01-19 20:45:03

Omni

Darn the broken post editing.

Posted on 2006-01-19 20:45:54

chanman

ahhh, i'm so dumn. I renamed myStr in the function call but forgot to change it in the code...

Posted on 2006-01-19 20:50:53

chanman

how come I can't edit my post? I spelled dumb wrong -_-*

Posted on 2006-01-19 20:51:54

Overkill

Yeah, er... there's an issue with the edit page right now. NOT ACCEPTABLE. I dunno what's up with that.

Posted on 2006-01-19 21:22:49


Displaying 1-9 of 9 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.