Awesome! TMU, if it helps with the confusion, you can call for
balls as integer[5, 5]
for i = 0 to 5
for j = 0 to 5
newsprite = createsprite(ball) //changed sprite name because we werent actually calling for i and j values
setspriteposition(newsprite, i * 100 + 100, j * 100 + 100) //had to add 100 for x and y to keep the first sprite at 100, 100
balls[i,j]=newsprite //here we insert the newsprite into the array using i and j values as x and y of array
next j
next i
and Part Time Coder, I had a feeling that might be the solution but didn't know if the loop would work. I'm going to try it now. here's what we have if anyone is interested =) Thanks a bunch! greenball and redball are attached
// Project: typearray
// Created: 2017-07-09
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "typearray" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 0, 0, 1, 0 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
greenball = loadimage("greenball.png") //move an image to the media folder and rename
redball = loadimage("redball.png")
balls as integer[9,7]
gametime = 0 //gametime is our counter for moving through the game 0 is starting and will prompt the name box to appear
for i = 0 to 9 //loop six times to make columns
for j = 0 to 7 //nested loop to fill each row
newsprite = createsprite(greenball) // the name newsprite will not be used. call sprites from array balls for example balls[1,3]
setspriteposition(newsprite, i * 104, j * 100) //sets sprite position to 0,0 for first sprite, 104, 0 for second sprite
//balls.insert(newsprite)
balls[i,j]=newsprite // insert newsprite into balls array using value of i and j for placement
next j // j loop will run values from 0 to 7 before i moves to next value
next i
redpoints = 0
greenpoints = 80
global myname$ as String
//cursor = createsprite(greenball) //makes a sprite for cursor (testing purposes)
//setspritegroup(cursor, 2)
do
if gametime = 0 and namebox = 0 //we use a counter for namebox so this if loop only runs once
createeditbox(1) //create the text box for users to input name with the id 1
SetEditBoxSize(1, 200, 50) //1 is the ID of the text box, 200 is width, 50 is height
seteditboxposition(1, 512-(GetEditBoxWidth(1)/2), 384 - (GetEditBoxHeight(1)/2)) //we set the position of the textbox (from its top left corner) to half the screen resolution and subtract half its length and width to center it
SetEditBoxTextSize(1, 30) //increase font size for users to see
SetEditBoxMaxChars(1, 15) //set max xharacters to 15
namebox = 1 //changing namebox will prevent this loop from reoccuring, and allow the next loop to run
createtext(0, "Your Name") //create "your name" text and position below editbox
SetTextSize(0, 50)
settextposition(0, geteditboxx(1), geteditboxy(1) + 70)
AddVirtualButton(3, geteditboxx(1) + 250, geteditboxy(1) + (GetEditBoxHeight(1)/2), 50) //create virtual button to submit name entry
endif
if gametime = 0 and namebox = 1
if GetVirtualButtonPressed(3)
// myname$ = GetTextInput() //this isnt working yet
DeleteVirtualButton(3)
DeleteEditBox(1)
deletetext(0)
gametime = 3
endif
endif
if gametime = 1
AddVirtualButton(1, 224, 300, 50)
AddVirtualButton(2, 800, 300, 50)
CreateText(1, "Host")
settextsize(1, 50)
SetTextPosition(1, 180, 350)
createtext(2, "Join")
SetTextSize(2, 50)
SetTextPosition(2, 766, 350)
gametime = 2
endif
if gametime = 2
endif
if gametime = 3
if getpointerpressed() = 1 and getspritehit(getpointerx(), getpointery()) > 0
if getspriteimageid(getspritehit(getpointerx(), getpointery())) = redball and click = 0
setspriteimage(getspritehit(getpointerx(), getpointery()), greenball)
setspritegroup(getspritehit(getpointerx(), getpointery()), 1)
click = 1
redpoints = redpoints - 1
greenpoints = greenpoints + 1
endif
endif
if getpointerpressed() = 1 and getspritehit(getpointerx(), getpointery()) > 0
if getspriteimageid(getspritehit(getpointerx(), getpointery())) = greenball and click = 0
setspriteimage(getspritehit(getpointerx(), getpointery()), redball)
setspritegroup(getspritehit(getpointerx(), getpointery()), 2)
click = 1
redpoints = redpoints + 1
greenpoints = greenpoints - 1
endif
endif
if GetPointerReleased() then click = 0
print(redpoints)
print(greenpoints)
print(myname$)
endif
// setspritepositionbyoffset(cursor, getpointerx(), getpointery()) //moves our cursor sprite to mouse position on screen
// if getspritecollision(cursor,balls[0,0] )
// setspriteimage(balls[0,0], redball)
//elseif getspritecollision(cursor, balls[0,0]) = 0
// setspriteimage(balls[0,0], greenball)
//endif
// Print( ScreenFPS() )
Sync()
loop
I will now try to implement the snippet you have attached, part time coder, as it seems much more practical than the jumbled up mess I currently have. After work I will let you know how it goes!
PS I know it needs to be cleaned up a little bit but this is a work in progress