2018-02-25 17:01:55

I'm not gonna be apologizing for using bgt heh, although I'm supposed to get around to learning something else. But after not having used it for years I figured I'd rewrite one of my favourite games - super deecout.
I could've used simpler code but I wanted the function to be reusable.
Anyway this throws up an error I can't seem to solve. I don't remember how to work with handles it seems.
class coin
{
double x;
double y;
coin()
{
}
}
coin@[] generate_coinmap(int coin_counter, int map_size)
{
coin@[] coinrun;
  coinrun.resize(coin_counter);
int tempy;
int tempx;
for(int counter=0; counter <coinrun.length()-1; counter++)
{
coinrun[counter].y=random(1, map_size);
coinrun[counter].x=random(1, map_size);
tempy=coinrun[counter].y;
tempx=coinrun[counter].x;
for(int counter2=0; counter2<=counter; counter2++)
{
if((coinrun[counter2].y==tempy)&&(coinrun[counter2].x==tempx))
{
counter--;
break;
}
}
}
return coinrun;
}
// this next part was just to test the coin list generator but is incomplete because of the runtime errors.
void main()
{
file lol;
coin@[] feck;
feck=generate_coinmap(20, 20);
string hunt;
lol.open("output.txt", "w");
for(int heh=0; heh<feck.length()-1; heh++)
{
hunt+""+feck[heh].y+", "+feck[heh].x+"\r\n";
}
}

Follow me on twitch
And
Subscribe to my youtube
Leave a thumbs up if you like what I write.

2018-02-25 17:42:23

what are the errors that you are getting?
and why did you open the file, if you aren't writing nothing to it?
you could do this though.
lol.open("output.txt", "w");
for(int heh=0; heh<feck.length()-1; heh++)
{
lol.write(hunt+""+feck[heh].y+", "+feck[heh].x+"\r\n");
lol.close();
}
}

Paul

2018-02-25 19:46:35

I would guess that coinrun starts out with the array full of nulls, rather than creating all the coins and their handles when you resize it, so you need to create coins before you try to modify them. So at the top of the for loop that sets the properties of the coins, you'd need two lines:
coin temp;
@coinrun[counter]=temp;
HTH

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2018-02-26 09:31:14

Hi.

@jotes I wanted to be more clean with the code as I wasn't sure how the file ... well I knew you could do that, it just seemed messy to me.

@Cae_Jones thanks, I'll try that. I actually attempted something similar but mine was inefficient and caused compilation errors tongue

Follow me on twitch
And
Subscribe to my youtube
Leave a thumbs up if you like what I write.