Re: BGT Coding Class
Hello, today we went over creating 2D arrays. Lucas will be posting the link to the recording soon. I'll post the code below.
This is just a simple program that creates a 2d array, then creates a second array with a list of names and assigns each value in the 2d array with a random name from the names provided in the name array.
coord, and use 0 through 19 for the y coord.
Press Y to type in the Y coord.
press x to type in your x coord.
Press enter to hear the name that was assigned to those values within the array.
Remember arrays are 0 based, so even though it says the length of the array is resized to 10, the entries are really 0-9 for the x array, and 0 through 19 for the y array.
Hope this helps!
string[][] array1;
string name;
void main()
{
show_game_window("Array Test");
string response;
int X;
int Y;
array1.resize(10);
for(int x=0; x<array1.length; x++)
{
array1
[x].resize(20);
}
string[] name(5);
name[0]="Vlad";
name[1]="Alex";
name[2]="Lucas";
name[3]="george";
name[4]="Conner";
do
{
for(int x=0; x<array1.length; x++)
{
for(int y=0; y<array1[x].length; y++)
{
array1[x][y]=name[random(0,4)];
}
}
if(key_pressed(KEY_X))
{
response =input_box("Coordinates lookup", "Enter the x coord you'd like to look up.", "");
X=string_to_number(response);
}
if(key_pressed(KEY_Y))
{
response =input_box("Coordinates lookup", "Enter the y coord you'd like to look up.", "");
Y=string_to_number(response);
}
if(key_pressed(KEY_RETURN))
{
alert("The data entry result", "Your coords resulted in the following name, "+array1[X][Y]);
}
if(key_pressed(KEY_ESCAPE))
{
break;
}
}
while(true);
}
_______________________________________________ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector