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

Previous topic - Next topic

Ian Price

You need to check if the mouse is being clicked and if it is, check where on the screen it is being clicked and if it's in a position that can be clicked make something happen.

So use something like
Code (glbasic) Select

IF b1

IF mx>xx and mx<xx+nn AND my>yy and my<yy+mm THEN do_something.

ENDIF



I came. I saw. I played.


Ian Price

Also, draw your cursor AFTER you draw the rects on the screen - then you can see it (as it is now it is drawn below the boxes).
I came. I saw. I played.

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
       
        MOUSESTATE mx, my, b1, b2
        IF b1

        IF mx>xx AND mx<xx+nn AND my>yy AND my<yy+mm THEN

        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 is my full code, I wasnt sure where to input the code you gave so I put in the main part

blackout12


Ian Price

Yep, I can see a couple of problems.

For starters -

Code (glbasic) Select
        IF b1

        IF mx>xx AND mx<xx+nn AND my>yy AND my<yy+mm THEN

        ENDIF

THEN.... what?

And secondly, you're going to get an out of bounds array error with this-
Code (glbasic) Select

IF x>=0 AND x>10 AND y>=0 AND y>10
set = playfield[x][y]

You've only got the playfield dimensioned for 10 arrays - if x>10 or y>10 then you're screwed. Change it to x<10 and y<10.
You are also using MOUSESTATE more than once in the main code.

And the Click(mx/32, my/32) won't give an integer number, causing errors. If you want ints, use GLOBAL mx%, my%

Your code is starting to get pretty messy now that you're expanding it too.
I came. I saw. I played.

blackout12

well, I am very new to this. so I didnt know what to put after "THEN", I dont know how to make the computer know that i want it to change the playfield. I am getting this code from the Help tutorial for the first game.

mentalthink

HI BLACKOUT I don't understand very well the question, but I put what I think you want answer...

What I put after the sentence THEN...

Well you can put a lot of things... some examples and I explain for what I use normally...

The first when you use Then or NOT use it, it's the same:

example

This 2 little codes are the same, always it's the same whit THEN or whit out it
  if a=true
     print "Hello" ,0,0
  endif

  if a=true then print "Hello",0,0

In fact you only say another things happends when some it's true or false , or you pur something like:

if a=10 and b<5 then print "true",0,0

But really I always use for leave fix somethiing:
Example

if a=true and RR=0 then lock_Move=true        ** RR I always use a constant RR=0 for make this sentence... this it's a mine

Now when I do this:
if lock_Move
  inc x
  print "move",x,0
endif

the text a, always runs to the right becuase the variable "lock_Move" it's fixed to true, and the "Move" letter goes to the right forever

An important in this prashe
if                         a  =  true and RR=0 then lock_Move=true   
This  variable       'a' not have to be always put to true, if I only leave for a millisecod in true and the a turns again to false

the move text I put more above always runs to the rights, this becuase happends?¿, very easy becuase when I say

if a  =  true (pass 1 ms and now it's false) and RR=0 then lock_Move=true   

the lock_Move variable has change to true, then I lock whit this sentence using the If and Then in conjunction...

I don't kwow If I'm expressed well, but if you need help whit this comment me... Basically I never use THEN, except when I do this...

Regards, and don't care about asking anything the forum it's for this, today I rebember whit MSX (friend of forum), when I started and I'm glad about her words, something... You advanced a lot of from you begin.... I'm some years ago was exactly in the same or minus point like you... Take with calm, pick and pick and pick more Code, and THEN 1 year later we speak again...  :booze: ;)


blackout12

I am trying to get the computer to change the playfield when I click on a certain block of the grid. I am using the Help guide and following it exactly but when it doesnt work I come here and ask Ian Price or anyone else that reads this post and mentalthink as well.
But the problem is that the help guide contradicts what you guys say and the answers I get off the forum work. So is the Help guide even accurate? If you go to help/tutorials/the first game "  you will see the code I am trying to program. If you read the above messages, you will see that the right way often contradicts the help guide :help:

erico

It could be, blackout12.

Thing is, that GLBasic gets updated on a very fast fashion, bugs are fixed, things and new platforms are implemented, etc.
That way, it is sometimes hard to keep up with the help files.

People with prior knowledge on BASIC can, sometimes, go around that and figure out for themselves.
If you are really new to GLBasic, my best bet is that you fast read the manual a couple times to get the general idea, then, you work on the PONG tutorial/demo, that+manual should give you a standard understandment on how BASIC works and is structured.

It is really simple, almost like writing an email in english.

Attempt to modify things on the pong game sounds like a good next step.
After such, you will be more confident to produce your own stuff.

I´m not sure how the tutorials may be not up to date, but I usually have GLBasic running and the f1(help) running on my other monitor and I use it a lot, specially on command descriptions.

Just so that you know, I´m no god coder at all, I´m quite a noob with the exception that I had prior exposition to BASIC on older computers.
I have learned BASIC on my own from books(no internet on the 80s  :'() and it was medium hard but I really wanted to make it happen and so I did.

What we say here, is related to our own experiences. The way Ian might solve a code is different then mine and is different then Mr. Tatoad and so on.
Each of us have developed a style on coding, and so must you.

It is from these different styles that we all learn from each other.
Feel free to come around and ask things you need. But it is important that you develop a style of your own.

So, sometimes, it is better for us to give you a hint on where you may look for a solution instead of pasting our own complete solutions.
That way, you will develop your own style.

Keep it up! :good:

kanonet

And an other tip:

programming means breaking everything down to its smallest possible steps. The computer is really dumb, so you need to tell him what to do in many really small steps.

Like: the computer does not know a playfield, he just knows the array that you use to display a playfield. So when you want to alter the playfield you need to alter the array. But tell him to change something on the array wont do much, cause you need to tell him how to change it in detail - and you dont want to change the whole array, you just want to change one element, right? So tell him exactly what element you want to change in which way.
Like for example: Playfield[3][3]=1-Playfield[3][3]
This wont do exactly what you want, but you should be able to modify this in order to get it working like you want it.

Btw. like erico said everyone has its own style of coding and solving problems, so when you ask how to do things and you get an answer that is different from the tutorial, that does not necessarily mean that the tutorial is wrong, its just an other way how to solve the problem. This is one of the cool parts of programming, you can solve one problem in thousands of different ways and its totally up to you which way you choose. I had a quick look at the tutorial, for me everything looks fine and should work. (Note that i just looked at the code, not at the text.)
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Moru

I tried the first tutorial again today and all I need to do is add the declarations for the variables for everything to work.

Code (glbasic) Select
GLOBAL playfield[]
GLOBAL mx, my, b1, b2
GLOBAL level, mousefree, clicks
GLOBAL set


Don't know if everything needs to be global though but it works. What does not work is to try to run the game over teamviewer from another computer. The mouse gets accelerated at least 10 times and it's impossible to hit anything.

blackout12


blackout12

Thank you guys so much for your help. I have figured out why my code isnt working...sort of. You see, no matter what I did to change my code for the game LOGO(I think) nothing mattered, when I clicked on the blue grid, nothing happened besides it registering how many times I clicked. As you would of guessed, this is very frustrating. So, I scrolled to the bottom of the help guide and copied and pasted the full code given. I expected that it would work, it did not, for some reason, even the master code given by the help did not allow me to change the grid when I clicked!!! Once before this happened to me when I was trying to do something else, I contacted GLBasic and found that I need to turn of explicit declarations. I did and it worked. This is different. does anyone have any idea why this is not working?!! :nw: :help: :help: :help:

fuzzy70

Here is mine copied straight from the help file & it works on my system no problems. Only thing I done was to turn off "Explicit Declarations" in the "Project Options" menu.

The code :

Code (glbasic) Select
// --------------------------------- //
// Project: OneMore

DIM playfield[10][10]

   level = 0

   // Main game
   start:
      IF IsLevelComplete()
         GOSUB NewLevel
         mousefree=FALSE
      ENDIF

      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:
   LOCAL x, y, color[]

DIM color[2]
   color[0] = RGB( 50,  50, 255) // Not set
   color[1] = RGB( 50, 255,  50) // Set

   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[x][y]]
      NEXT
   NEXT
   PRINT "Clicks: "+clicks, 360, 120
   PRINT "Level:  "+level, 360, 160
ENDSUB // SHOWPLAYFIELD


// ------------------------------------------------------------- //
// -=#  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


// ------------------------------------------------------------- //
// -=#  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
      // or simply:
      // set = 1-set
      playfield[x][y]=set
   ENDIF
ENDFUNCTION


// ------------------------------------------------------------- //
// -=#  NEWLEVEL  #=-
// ------------------------------------------------------------- //
SUB NewLevel:
   LOCAL x, y, i

   // Clear playfield - just to be sure
   FOR x=0 TO 9
      FOR y=0 TO 9
         playfield[x][y]=FALSE
      NEXT
   NEXT

   level=level+1
   
   // Do random clicks
   FOR i=0 TO level
      Click(RND(9), RND(9))
   NEXT
   clicks=0
   GOSUB ShowPlayfield
   PRINT "Level: "+level + " - get ready", 0, 360
   SHOWSCREEN
   MOUSEWAIT
ENDSUB // NEWLEVEL


// ------------------------------------------------------------- //
// -=#  ISLEVELCOMPLETE  #=-
// ------------------------------------------------------------- //
FUNCTION IsLevelComplete:
   LOCAL x, y

   FOR x=0 TO 9
      FOR y=0 TO 9
         IF playfield[x][y]=TRUE THEN RETURN FALSE
      NEXT
   NEXT
   RETURN TRUE
ENDFUNCTION


I have also attached the compiled result & the project files for you to test on your system. Try the exe 1st then open the project & run it to see if both work ok. If not then there is something odd going on with your system. I deliberately left out adding the GLOBAL/LOCAL declarations to the code as to keep it an exact copy of the code posted in the help file.

Out of interest I presume you are compiling for Windows & not another target that GLBasic supoorts.

Also attached is my version of that game as like yourself it was one of the 1st things I played with after discovering GLBasic. I never got round to finishing it off completely as learnt what I needed & moved on to other things  :D

Lee

[attachment deleted by admin]
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)