Help for NEWBIES. NOTE: I am a newbie so I cant really help.

Previous topic - Next topic

blackout12

// -------------------------------- //
// my first game

DIM Playfield[10][10]
    level = 0
     main:
        MOUSESTATE mx, my, b1, b2
        PRINT "<>", mx, my-8
        SHOWSCREEN
     GOTO main
END





// ------------------------------------------------------------- //
// -=#  SHOWPLAYFIELD  #=-
// ------------------------------------------------------------- //
SUB ShowPlayfield:
    LOCAL x, y, color[]
   
DIM color[2]
    color[0] = RGB ( 50,  50, 255)
    color[1] = RGB ( 50, 255,  50)
   
    DRAWRECT 0,0, 320, 320, RGB(255,255,255)
    FOR x=0 TO 9
       FOR y=0 TO 9
          DRAWRECT x*32+1, y*32+1, 30, 30, color[playfield
  • [y]]
           NEXT
        NEXT
        PRINT "Clicks: "+clicks, 360, 120
        PRINT "Level:  "+level, 360, 160

    ENDSUB // SHOWPLAYFIELD


    this isnt working please help

blackout12

// -------------------------------- //
// my first game

DIM Playfield[10][10]
    level = 0
     main:
        MOUSESTATE mx, my, b1, b2
        PRINT "<>", mx, my-8
        GOSUB showplayfield
        SHOWSCREEN
     GOTO main
END





// ------------------------------------------------------------- //
// -=#  SHOWPLAYFIELD  #=-
// ------------------------------------------------------------- //
SUB ShowPlayfield:
    LOCAL x, y, color[]
   
DIM color[2]
    color[0] = RGB ( 50,  50, 255)
    color[1] = RGB ( 50, 255,  50)
   
    DRAWRECT 0,0, 320, 320, RGB(255,255,255)
    FOR x=0 TO 9
       FOR y=0 TO 9
          DRAWRECT x*32+1, y*32+1, 30, 30, color[playfield
  • [y]]
           NEXT
        NEXT
        PRINT "Clicks: "+clicks, 360, 120
        PRINT "Level:  "+level, 360, 160

    ENDSUB // SHOWPLAYFIELD


    I meant this, I forgot GOSUB, but it still doesnt work

MrTAToad

You need to put the code between [ code] & [ /code] blocks as there are bits missing...

Ian Price

Well the above code has a SYNTAX ERROR due to "[y]]" being cut off of "color[Playfield[" , but other than non-declared variables (I presume you don't use Explicit Declaration) then it works. It doesn't do anything with the Show_Playfield section, but the "main:" loop works. [EDIT] This was entered before the GOSUB bit was added.

The problem is you are trying to DRAWRECT with color[y] - when you've already stated that y is a value between 0 and 9. You've defined the colour dimension to accept only 2 values (0 and 1). You've gone out of bounds with the array value.

Put this at the start of your code -

Code (glbasic) Select

GLOBAL color[]

DIM color[100]
    color[0] = RGB ( 50,  50, 255)
    color[1] = RGB ( 50, 255,  50)

And remove the local color[] from the SUB.

Then it works.
I came. I saw. I played.


blackout12

// -------------------------------- //
// my first game
GLOBAL color[]

DIM color[100]
    color[0] = RGB ( 50,  50, 255)
    color[1] = RGB ( 50, 255,  50)
DIM Playfield[10][10]
    level = 0
     main:
        MOUSESTATE mx, my, b1, b2
        PRINT "<>", mx, my-8
        GOSUB ShowPlayfield
        SHOWSCREEN
     GOTO main
END





// ------------------------------------------------------------- //
// -=#  SHOWPLAYFIELD  #=-
// ------------------------------------------------------------- //
SUB ShowPlayfield:

    DRAWRECT 0,0, 320, 320, RGB(255,255,255)
    FOR x=0 TO 9
       FOR y=0 TO 9
          DRAWRECT x*32+1, y*32+1, 30, 30, color[playfield
  • [y]]
           NEXT
        NEXT
        PRINT "Clicks: "+clicks, 360, 120
        PRINT "Level:  "+level, 360, 160

    ENDSUB // SHOWPLAYFIELD


    is this what you meant? It doesnt work

erico

First, when posting code:

1-select all your code from GLBasic and do a ctrl+C
2-when doing a post with code on these forums, write your messege normally but  hit that button (#) right over the smiles, press crtl+V so your code is between  [ code] & [ /code]  like Mr.T said.

If it dosen´t look like what it should be, you can always edit a post to get it right.
The reason for this is that people around here will actually be able to fast test your code, so, you get a faster answer.

I took a look and it seems you are using variables like "playfield" and "Playfield". GLB will read that as different variables so you want to be really carefull when naming them. Specially on the caps lock things.

I did mess with it a bit and it works, but I had to declare the variables on my end.
Here is the code:
Code (glbasic) Select

// my first game

// declarations
GLOBAL color[]
GLOBAL Playfield[]
GLOBAL mx,my,b1,b2,x,y,level, clicks

DIM color[100]
    color[0] = RGB ( 50,  50, 255)
    color[1] = RGB ( 50, 255,  50)
   
DIM Playfield[10][10]
    level=0
    main:
        MOUSESTATE mx, my, b1, b2
        PRINT "<>", mx, my-8
        GOSUB ShowPlayfield
        SHOWSCREEN
    GOTO main
END



// ------------------------------------------------------------- //
// -=#  SHOWPLAYFIELD  #=-
// ------------------------------------------------------------- //
SUB ShowPlayfield:

    DRAWRECT 0,0, 320, 320, RGB(255,255,255)
    FOR x=0 TO 9
       FOR y=0 TO 9
          DRAWRECT x*32+1, y*32+1, 30, 30, color[Playfield[y]]
       NEXT
    NEXT
    PRINT "Clicks: "+clicks, 360, 120
    PRINT "Level:  "+level, 360, 160

ENDSUB // SHOWPLAYFIELD


and appended is a picture of what I get.

[attachment deleted by admin]

mentalthink

Yes blackout try to put the code bewtween the tags, it's more easy and readable for us...
If you not are sure if works, you can press the button preview and then you can see , else you can edit after the post.

blackout12


erico

It is fine.

But don´t forget to let us know if it worked on your end. :good:


blackout12

Code (glbasic) Select
// my first game


GLOBAL color[]
GLOBAL Playfield[]
GLOBAL mx,my,b1,b2,x,y,level, clicks

DIM color[100]
    color[0] = RGB ( 50,  50, 255)
    color[1] = RGB ( 50, 255,  50)

DIM Playfield[10][10]
    level=0
    start:
        MOUSESTATE mx, my, b1, b2
        IF b1
           IF mousefree THEN Click(mx/32, my/32)
           mousefree=FALSE
        ELSE
           mousefree=TRUE
        ENDIF
        GOSUB ShowPlayfield
        PRINT "<>", mx, my-8
        SHOWSCREEN
    GOTO start
END



// ------------------------------------------------------------- //
// -=#  SHOWPLAYFIELD  #=-
// ------------------------------------------------------------- //
SUB ShowPlayfield:

    DRAWRECT 0,0, 320, 320, RGB(255,255,255)
    FOR x=0 TO 9
       FOR y=0 TO 9
          DRAWRECT x*32+1, y*32+1, 30, 30, color[Playfield[y]]
       NEXT
    NEXT
    PRINT "Clicks: "+clicks, 360, 120
    PRINT "Level:  "+level, 360, 160

ENDSUB // SHOWPLAYFIELD


// ------------------------------------------------------------- //
// ---  CHANGE  ---
// ------------------------------------------------------------- //
FUNCTION Change: x, y
// These values are defined LOCAL:
// x,  y
IF x>=0 AND x>10 AND y>=0 AND y>10
   set = playfield[x][y]
   
   IF set = TRUE
      set=FALSE
   ELSE
      set=TRUE
   ENDIF
   playfield[x][y]=set
ENDIF
ENDFUNCTION







// ------------------------------------------------------------- //
// ---  CLICK  ---
// ------------------------------------------------------------- //
FUNCTION Click: x, y
// These values are defined LOCAL:
    // x,  y
    clicks=clicks+1
    Change(x-1, y)
    Change(x+1, y)
    Change(x, y)
    Change(x, y-1)
    Change(x, y+1)
ENDFUNCTION





this did not work

blackout12

the board showed but nothing happened when I clicked

Ian Price

Quotethe board showed but nothing happened when I clicked
Perhaps that's because there is no click routine in your code?
I came. I saw. I played.

blackout12

how would you go about making a click routine?