ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

New to FreeBASIC? Post your questions here.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by BasicCoder2 »

@Trinity,
Yes I agree "tips and tricks" is not organized for a beginner and the examples vary from those written by highly advanced sophisticated programmers on this forum and some less than ideal examples because the author isn't on top of everything (me!!). As MrSwiss pointed out poor examples from myself can result in a beginner not really getting the best examples of how it is best done. Not much I can do about that except maybe to stop posting anything but questions as I don't have the time or inclination to get up to speed with all of the latest and greatest with regards to FreeBasic. I was using FreeBASIC for its QBASIC like features not its advanced stuff.
... then you already completely lost me because something that is the most natural to you because you know is like gibberish to me , ...
That happens to me all the time when I look at the code written by the advanced programmers on this forum and I have been here for a long time!!
For you reading this it's like I am a fool for not knowing what you perhaps find fundamental knowledge ?
Not at all. I am in the same boat. I can't read most of the programs written on the forum because they use advanced features of FreeBasic. I usually limit myself to a few commands from QBASIC I am familiar with. QBASIC did use TYPES although I found parallel arrays easier to understand back then. I don't use OOP although I am familiar with it from tutorials I did many years ago found in books like "C++ for Dummies" :)
It would be a completely different situation if you and I were sitting next to each other with each our PC so I could ask you every time there were something that I couldn't grasp ,
Felt the same way when trying to hook up SDL and other libraries to CODE::BLOCKS an IDE I was using with C++. I failed by the way even after trying to follow the instructions (without understanding) as carefully as I could.

Have you attempted to work your way through any FreeBasic tutorial?
http://homepage.univie.ac.at/hans.leo.n ... ginner.pdf
http://www.frankticfreebasic.com/

You don't have to know everything before programming you only have know the commands you are using. I cannot for example read dodicat's highly compact fast 3d programs or any of the OOP examples from the better programmers so I don't bother as I am happy being an old retro programmer using FreeBASIC as I used QBASIC but with fast graphics with 24 bit pixels and lots of memory not available on the old machines.

With regards to the topic this was how I did my edit box on the old machines.
viewtopic.php?f=7&t=20934&hilit=editor
Are you able to read the code?
I used to mostly code in assembler because back then it was nice and fast and easy to learn as there weren't that many commands (instructions) on the old cpu or complex high level language data structures just a list of 8 bit numbers called the memory and a few cpu variables (registers).
.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by dodicat »

Trinity.
In these types you are allowed to use certain FreeBASIC keywords.
I use type circle and declare sub draw
So Circle and draw I have used.
It would probably be better if I had used type MyCircle and used Show instead of draw.
I can see the confusion, I should have noticed that.
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by Trinity »

MrSwiss wrote:This means, translated to "everyday language":
  • object = type
  • member = a variable (inside a type, therefore a: *type.member*)
  • reference = directly accessible (only if declared Public: -- unlike a pointer, which would need dereferencing, first)
A maybe better explanation of those terms, can be found at: GlossaryIndex
Thank you , so that would make "Returns a reference to a member from a reference to an object" = "Returns a reference to a type member from a reference to a type" ;-) , I think that it is still think that it sounds something like A refers to B and B refers to A , and that that is supposed to make people wise or tell people anything ;-) :-D
(Don't worry , I think that I just need to take my time getting to know it :-) )

I wasn't even aware that there were a glossary - I do not know how I missed that...
Thank you :-)
BasicCoder2 wrote:Not much I can do about that except maybe to stop posting anything but questions as I don't have the time or inclination to get up to speed with all of the latest and greatest with regards to FreeBasic. I was using FreeBASIC for its QBASIC like features not its advanced stuff.
No , no , you ought *not* stop posting your stuff. And the fact that someone else thinks that something else is better does not matter in that connection. I will quote you yourself if that helps :
"You don't have to know everything before programming you only have know the commands you are using. I cannot for example read dodicat's highly compact fast 3d programs or any of the OOP examples from the better programmers so I don't bother as I am happy being an old retro programmer"
And then my question would be : so you think that you are the only one like that ? Meaning that maybe there are other people that prefer to read that over the more advanced stuff which may be better but still too advanced for them !
BasicCoder2 wrote: I usually limit myself to a few commands from QBASIC I am familiar with.
So funny that you should choose to write that because that was my attitude , I mean so much better to write something really nice with what you have a good grasp of rather than trying to write advanced code but a poor program.
But I would like to confess that I will still try to get better and that includes hopefully get a very firm grasp of everything I want to.
But for the years that has passed then I have had the attitude mentioned.
BasicCoder2 wrote: I failed by the way even after trying to follow the instructions (without understanding) as carefully as I could.
I have tried to compile stuff more times on different platforms (Linux and Win , not that I yet really use Linux) and IDEs as part of trying to get to know the IDE but failed miserably always (Prior to using FB), I am not even sure if I have compiled a "Hello World" other than Borland Pascal maybe (?)
BasicCoder2 wrote: Have you attempted to work your way through any FreeBasic tutorial?
No , I didn't know of these , anyway , I am not very good at using tutorials , I usually get bored too soon. E.g. I have made serious attempts to learn C and C++ more times but never did much more the first few chapters or whatever - still have a 7 pages C learning notes made on C study and the last entry is about C data-types which ought to tell how far I got there (LOL)
BasicCoder2 wrote: You don't have to know everything before programming you only have know the commands you are using.
My point exactly (also see other above reference to same)
BasicCoder2 wrote: Are you able to read the code?
.
Yes and no , Yes , I can read it , but no , because I have not progressed as far as you yet in general (though I get a feeling that my progression may not become linear but rather in spots jumping all over the place ;-) :-D ) , you use draw and color which I have not made any real acquaintance with yet outside other peoples code. The rest I can read the principles of it from your comments but there is long way from that to actually following your code which would take me one or more hours (?) to do I think..
But I think that in general it's hard to follow other peoples code. if much more than snippets that is .

Keep on coding BasicCoder2 , I am sure that FB can give us all a lot of well coded stuff if for nothing else then at least for our own use which I am sure that you are already fully aware of :-)
dodicat wrote:Trinity.
In these types you are allowed to use certain FreeBASIC keywords.
<Snip>
It would probably be better if I had used type MyCircle and used Show instead of draw.
I can see the confusion, I should have noticed that.
No problem , but thank you very much for taking your time specifying.
I at least learned or got re-acquainted with that you are allowed to use certain Keywords in type definitions ;-)
But your example code never the less seem to actually have helped me get a beginners grasp of the whole OOP thing which is actually a lot considering the many times I have wished that I understood and tried to get to understand :-)
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by dodicat »

Trinity.
Why not as an exercise, declare another function inside the type to calculate the area of a circle, and print this value inside the green and orange circles, using the existing draw (or show) sub.
Maybe you could use draw string to show the value instead of print.
So I recommend calling the sub draw something else.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by BasicCoder2 »

Trinity wrote:I am not very good at using tutorials , I usually get bored too soon.
Ok. Well that is a problem I think. Maybe the tutorials are too boring? What is it you want to program? It is like asking someone who wants to write what they want to write about. If you have nothing to say then there is no need to write anything. If you have nothing you want your hardware to do then there is no point learning to program.
... I get a feeling that my progression may not become linear but rather in spots jumping all over the place ;-) :-D )
Yes I think you are learning too little about too much. Best to start with the the FreeBASIC way of doing what I gather you already know from previous experience. Don't be quick to jump into OOP until you have a firmer grasp of simple FreeBASIC statements such as using TYPE.
... you use draw and color which I have not made any real acquaintance with yet outside other peoples code.
Fair enough. I can see I haven't restricted myself to old standard BASIC commands but I could have done so if required.

Essentially I think we program top/down and the difficulty with other people's code, even if you are familiar with the commands being used, is that you have to reverse the process. It is better to explain what is happening at a high level (human language, diagrams, equations) and then translate down to the computer language of your choice.

For example I can explain how Bresenham's algorithm works without using any code at all. You can then use that understanding to translate it into any computer language you like as I have done many times. For example the current LINE statement has no pen size so you write your own version with PEN SIZE as an extra parameter. Essentially you add your own statements to the language when you use a sub or function.

Code: Select all

drawLine (x1,y1,x2,y2,penSize,penColor)
or

Code: Select all

drawLine (x1,y1,angle,length,penSize,penColor)
which gives the angle (slope) of the line and length of line instead of the end points. Other variants are also possible.

This is where overloading shows its value as it uses the parameter list to recognize which version of drawLine you are using.
.
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by paul doe »

Hi Trinity
Trinity wrote: Yes and no , Yes , I can read it , but no , because I have not progressed as far as you yet in general (though I get a feeling that my progression may not become linear but rather in spots jumping all over the place ;-) :-D ) , you use draw and color which I have not made any real acquaintance with yet outside other peoples code. The rest I can read the principles of it from your comments but there is long way from that to actually following your code which would take me one or more hours (?) to do I think..
But I think that in general it's hard to follow other peoples code. if much more than snippets that is .
Having had too much wine tonight, I now feel generous and will make an attempt to explain to you in some very simple steps what this OOP stuff that troubles you is all about, so you can (maybe) at least be able to read other people's code ;-)
Do be aware, however, that this isn't OOP by any stretch of the imagination (confused, yet?). Just pretend, for learning purposes, that it is, ok? Very well. Suppose that I want FB to draw a rectangle, and I want to be sophisticated and do it in OOP (sort of). First, I tell the FB compiler that I will be explaining to it what a rectangle is:

Code: Select all

type rectangle

end type
But, this isn't enough for the compiler to 'get it'. A rectangle is an object, and an object has attributes (called 'properties' in OOP jargon), right? Like, for example, it's position in the screen:

Code: Select all

type rectangle
	as integer positionX
	as integer positionY
end type
Much better. But alas, the compiler still doesn't know how to draw it. It now knows where to place it, but not how big it is, or the color it has. We can tell it that a rectangle also has a width, and a height, and a color:

Code: Select all

type rectangle
	as integer positionX
	as integer positionY
	as integer width
	as integer height
	as integer color
end type
Now, the compiler has enough information to represent a rectangle, right? You bet. But, it's still unable to draw it. Why? Because we hadn't tell it which procedure will do it:

Code: Select all

type rectangle
	as integer positionX
	as integer positionY
	as integer width
	as integer height
	as integer color

	declare sub drawIt()
end type
That's it. Now, FB knows that a rectangle is an entity that has a position, width, height, a color, and that the user can tell the rectangle to draw itself (using drawIt() ). Time to tell the compiler how to drawIt():

Code: Select all

type rectangle
	as integer positionX
	as integer positionY
	as integer width
	as integer height
	as integer color

	declare sub drawIt()
end type

sub rectangle.drawIt()
	line( positionX, positionY ) - ( positionX + width - 1, positionY + height - 1 ), color, bf
end sub
We are getting somewhere. All that's left is to setup a screen mode, create a rectangle with our desired properties, and tell it to draw itself ('cuz I say so!):

Code: Select all

'' define what a rectangle is
type rectangle
	as integer positionX
	as integer positionY
	as integer width
	as integer height
	as integer color

	declare sub drawIt()
end type

'' tell the rectangle class what it means to 'drawIt'
sub rectangle.drawIt()
	line( positionX, positionY ) - ( positionX + width - 1, positionY + height - 1 ), color, bf
end sub

'' set a graphical window
screenRes( 800, 600, 32 )

'' create a rectangle ('instantiating' is the word used in OOP)
'' here we instantiate one named 'rect'
dim as rectangle rect

'' set the rectangle attributes ('properties')
'' the with block tells the compiler that we are, precisely, working 'with' the
'' rectangle 'rect'
with rect
	.positionX = 100
	.positionY = 100
	.width = 200
	.height = 100
	.color = rgb( 255, 0, 0 )
end with

'' finally, tell the rectangle to draw itself. This, in OOP, it's called a 'method'
rect.drawIt()

'' wait a key press
sleep()
That's what the dot means in this context. It's telling the compiler that we are referencing a certain property or method of the type or object. To change its color, for example, we write

Code: Select all

'' rgb is a FB macro. See the documentation for details
rect.color = rgb( 0, 255, 0 )

'' and draw it, of course
rect.drawIt()
which makes the rectangle green. Hence, the 'with' construction in the code. It saves us from having to type 'rect.xxx' every time, which is very convenient, no?
As you can hopefully see, it isn't difficult, just verbose. Maybe this simple example will help you begin to grasp the FB concept of 'types as objects'. Feel free to object the code, and also to forgive my typos. I've had too much wine and english isn't even my native tongue X-D

Best of luck
Paul

EDIT: 30 seconds later, had to edit it because I posted the same thing. Twice. In the same post.
EDIT2: 45 seconds later, edited because I accidentally erased the last part of the post. Damn. I'm going to bed.
xlucas
Posts: 334
Joined: May 09, 2014 21:19
Location: Argentina

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by xlucas »

Trinity: Don't worry if this form of coding (being object-oriented or not quite, but kind of) seems uncomfortable to you. I started with QuickBasic back in the early 90s and QB did not have these features. I taught myself some C later on, but even though I had a C++ compiler, I would use it as a C and when I got to FreeBasic, although I did always use the FB dialect instead of sticking to QB, I never adopted the OOP or Type-Oriented programming style simply because it was not comfortable to me. It's been years and I understand I can read OOP (let me say it that way for simplicity), but it is always much, much clearer to me to read non-OOP code and without using the new paradigm, I can still program every kind of project I like. It is definitely important that you know and understand what OOP is about, but using it yourself is not. The best form of programming is the one that makes you feel the most comfortable. I think the other guys will agree with me at that.

Paul Doe: Hey, compatriota!!!
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by paul doe »

xlucas wrote:Trinity: Don't worry if this form of coding (being object-oriented or not quite, but kind of) seems uncomfortable to you. I started with QuickBasic back in the early 90s and QB did not have these features. I taught myself some C later on, but even though I had a C++ compiler, I would use it as a C and when I got to FreeBasic, although I did always use the FB dialect instead of sticking to QB, I never adopted the OOP or Type-Oriented programming style simply because it was not comfortable to me. It's been years and I understand I can read OOP (let me say it that way for simplicity), but it is always much, much clearer to me to read non-OOP code and without using the new paradigm, I can still program every kind of project I like. It is definitely important that you know and understand what OOP is about, but using it yourself is not. The best form of programming is the one that makes you feel the most comfortable. I think the other guys will agree with me at that.

Paul Doe: Hey, compatriota!!!
@Trinity: xlucas is right. OOP is only a 'paradigm', a way of conceptualizing and modeling things. FB is a 'multiparadigm' language (it lets you mix traditional procedural programming and OOP), Java is not (you can only do OOP). And as xlucas points out, it's perfectly possible to write OOP using procedural programming only.

@xlucas: ¡Eh, que haciendo, che! ¿De qué parte de Argentina sos? ¡Mirá por donde nos venimos a encontrar loco jaja! Estoy preparando algo para otro forista que quiere aprender 3D, capaz querés mirarlo también. Ni bien lo termine lo cuelgo acá. Pasa que tengo que sacarle un montón de código y adaptarlo, sino se le va a enquilombar más la cabeza al pobre. Un abrazo che, nos vemos por acá. Y si no nos vemos nos tanteamos...
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by Trinity »

dodicat wrote:Why not as an exercise, declare another function inside the type to calculate the area of a circle, and print this value inside the green and orange circles, using the existing draw (or show) sub.
Why do I get the impression that "Dodicat" 's "learn kids to swim in 30 minutes" course consists of Dodicat dragging the kid down to the pier without learning it swim movements first and then throw the kid into the water ? ;-) :-D
Translated :
I spent around four hours trying to find out how to put the "Draw String" into existing draw sub , but code would not be accepted by compiler who kept saying expected End Of Line. So apparently one are not allowed to use reference to something unless one first make it a type (?) , Dunno , your use of Circle as name of type as well as (necessarily) as statement to draw the circle did not further my understanding of that.
Then today I spent 30 minutes trying to use name references in sub that were not allowed - got something about Static or Non-Static and maybe illegal use (?)
Anyway , I have put the text into the circles as you asked but could not find out how to do it using method requested by you.
My problem , apart from very little understanding of what I was doing , is that I would have to acquire at least manual level of understanding of all the stuff , and because my knowledge of it is so low then it seem like far too much for me now to try to learn it all and .

After having spent hours trying to do as requested then I have really not understood much of why it wouldn't work, so I just copied code and altered it to look as something that would work.. which it then did.
Here is the code I came up with :

Code: Select all

Const Pi=4.0*ATN(1.0)

type circle
    as integer radius
    as integer cx  'centre x value
    as integer cy  'centre y value
    as uinteger colour
    declare sub draw
End type

Type Draw
    as integer dx  'centre x value
    as integer dy  'centre y value
    as integer area
    as string mystring
    declare sub areainfo    
end type

sub circle.draw
circle(cx,cy),radius,colour,,,,f
'or
'circle(this.cx,this.cy),this.radius,this.colour,,,,f
end sub

sub Draw.areainfo
Draw String(dx,dy), mystring 
end sub

dim as circle A
'option 1
A.radius=50
A.cx=400
A.cy=300
a.colour=6

dim as circle B
'option 2
with B
    .radius=80
    .cx=600
    .cy=300
    .colour=2
end with

Dim as Draw DA
'option 1
DA.area=Pi*(A.radius*A.radius)
DA.mystring = "area = "&Str(DA.area)
'  Having not worked with X,Y coordinate systems in many years I am still confused so I confuse X and Y all the time
'  Doesn't matter here - can't tell here when fonts are 8 * 8 pixels
DA.dx = (A.cx-(len(DA.mystring)/2)*8) ' subtracted len(DB.mystring) divided by 2 and multiplied by expected font width to center text 
DA.dy = A.cy-4  ' subtracted half of expected font height to center text  

Dim as Draw DB
With DB
'option 2
.area=Pi*(B.radius*B.radius)
.mystring = "area = "&Str(DB.area)    
.dx = (B.cx-(len(DB.mystring)/2)*8)   
.dy = B.cy-4  
end with

screen 19

A.draw
B.draw
DA.areainfo
DB.areainfo

sleep
BasicCoder2 wrote:What is it you want to program? It is like asking someone who wants to write what they want to write about. If you have nothing to say then there is no need to write anything. If you have nothing you want your hardware to do then there is no point learning to program.
Asking me "What is it you want to program?" is like asking very poor people with big dreams what they would like to do if they had more money than the worlds richest put together...
But I will drop that discussion entirely other than in short stating that my immediate goals are the the fulfillment of some personal programming goals set out a long time ago (I think that it is probably all in vain but I will do it anyway)
BasicCoder2 wrote:Yes I think you are learning too little about too much. Best to start with the the FreeBASIC way of doing what I gather you already know from previous experience. Don't be quick to jump into OOP until you have a firmer grasp of simple FreeBASIC statements such as using TYPE.
You are right that I ought to start with what I already know , and that is also exactly what I have been doing. However , some features of my previously used TI Extended BASIC must be done in another way and also everybody here knows about the problem that this thread is originally about so it has been completely unavoidable. Also you can't do without I/O , both to and from screen/KB/mouse(?) but also file operations. And all that is considerably more complex (but also with *many more* features) than if using and old BASIC dialect. Throw in all the differences from old to new with respect to variables, arrays and what not , then you will have to realize that you can not just stick with using what you know because that is far too little (and again remember I did not come from QB , I come from TI ExtB).
The only thing I can do to limit the new is to try only fan out as far as needed what's needed to work towards fulfilling present greater programing goals, but all the discussion before you is only a result of the initial post in this thread - a post that was about stuff that for me is still pretty basic , and about basic I/O and screen control ;) :-D Anyway , it has to fan out but hopefully not too much too fast.
BasicCoder2 wrote:It is better to explain what is happening at a high level (human language, diagrams, equations) and then translate down to the computer language of your choice.
Thank you very much for your explanation :-)
paul doe wrote:Having had too much wine tonight, I now feel generous and will make an attempt to explain to you in some very simple steps what this OOP stuff that troubles you is all about, so you can (maybe) at least be able to read other people's code ;-)
Thank you very much for being so kind as to cut things into small step by step snippets for me. It was nice thank you :-)
paul doe wrote:Feel free to object the code, and also to forgive my typos. I've had too much wine and english isn't even my native tongue X-D
I think that you are doing extremely well with your English and writing for a person that have had too much wine and who do not have English as mother tongue :-)
paul doe wrote: xlucas is right. OOP is only a 'paradigm', a way of conceptualizing and modeling things. FB is a 'multiparadigm' language (it lets you mix traditional procedural programming and OOP), Java is not (you can only do OOP). And as xlucas points out, it's perfectly possible to write OOP using procedural programming only.
Thank you for clarifying :-)
xlucas wrote:The best form of programming is the one that makes you feel the most comfortable. I think the other guys will agree with me at that.
Though we may evolve over time then as a starting point of view then you are absolutely right. Thank you :-)
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by fxm »

dodicat wrote:Trinity.
Why not as an exercise, declare another function inside the type to calculate the area of a circle, and print this value inside the green and orange circles, using the existing draw (or show) sub.
Maybe you could use draw string to show the value instead of print.
So I recommend calling the sub draw something else.
Trinity, I Think that dodicat expects rather a code as following:

Code: Select all

Const Pi=4.0*ATN(1.0)

type circle
    as integer radius
    as integer cx  'centre x value
    as integer cy  'centre y value
    as uinteger colour
    declare sub show
    declare sub areainfo   
End type

sub circle.show
  circle(cx,cy),radius,colour,,,,f
end sub

sub circle.areainfo
    dim as integer dx, dy, area
    dim as string mystring
    area=Pi*(radius*radius)
    mystring = "area = "&Str(area)
    dx = (cx-(len(mystring)/2)*8) ' subtracted len(mystring) divided by 2 and multiplied by expected font width to center text
    dy = cy-4                     ' subtracted half of expected font height to center text 
    draw string(dx,dy), mystring
end sub

dim as circle A
'option 1
A.radius=50
A.cx=400
A.cy=300
a.colour=6

dim as circle B
'option 2
with B
    .radius=80
    .cx=600
    .cy=300
    .colour=2
end with

screen 19

A.show
B.show
A.areainfo
B.areainfo

sleep
For a Beginner and even everyone, it is easier (and better) to always define procedure (and variables) names different from the keywords.
Otherwise, there is a special syntax:
documentation wrote:To access duplicated symbols defined in the global namespace, use: .SomeSymbol (or ..SomeSymbol if inside a With..End With block).
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by Trinity »

fxm wrote:I Think that dodicat expects rather a code as following:
Thanks FXM , but I had major problem putting variable names and dot references into the Sub without compiler giving errors so I just gave that up and did what I did , that way at least I could get the Sub to accept the Draw statement which were the only way for me.
fxm wrote: it is easier (and better) to always define procedure (and variables) names different from the keywords
I couldn't put the Draw String statement into the sub circle.show (compiler errors) as I wanted so it looked to me as I had to make a Type called Draw to be able to use the Draw String
(and Draw String was not duplicated symbol from somewhere else either)
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by fxm »

fxm wrote:For a Beginner and even everyone, it is easier (and better) to always define procedure (and variables) names different from the keywords.
Otherwise, there is a special syntax:
documentation wrote:To access duplicated symbols defined in the global namespace, use: .SomeSymbol (or ..SomeSymbol if inside a With..End With block).
Example:

Code: Select all

Const Pi=4.0*ATN(1.0)

type circle
    as integer radius
    as integer cx  'centre x value
    as integer cy  'centre y value
    as uinteger colour
    declare sub draw
End type

sub circle.draw
    dim as integer dx, dy, area
    dim as string mystring
    circle(cx,cy),radius,colour,,,,f
    area=Pi*(radius*radius)
    mystring = "area = "&Str(area)
    dx = (cx-(len(mystring)/2)*8) ' subtracted len(mystring) divided by 2 and multiplied by expected font width to center text
    dy = cy-4                     ' subtracted half of expected font height to center text 
    .draw string(dx,dy), mystring
end sub

dim as circle A
'option 1
A.radius=50
A.cx=400
A.cy=300
a.colour=6

dim as circle B
'option 2
with B
    .radius=80
    .cx=600
    .cy=300
    .colour=2
end with

screen 19

A.draw
B.draw

sleep
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by fxm »

Trinity wrote:I couldn't put the Draw String statement into the sub circle.show (compiler errors) as I wanted so it looked to me as I had to make a Type called Draw to be able to use the Draw String
(and Draw String was not duplicated symbol from somewhere else either)
Example:

Code: Select all

Const Pi=4.0*ATN(1.0)

type circle
    as integer radius
    as integer cx  'centre x value
    as integer cy  'centre y value
    as uinteger colour
    declare sub show
End type

sub circle.show
    dim as integer dx, dy, area
    dim as string mystring
    circle(cx,cy),radius,colour,,,,f
    area=Pi*(radius*radius)
    mystring = "area = "&Str(area)
    dx = (cx-(len(mystring)/2)*8) ' subtracted len(mystring) divided by 2 and multiplied by expected font width to center text
    dy = cy-4                     ' subtracted half of expected font height to center text 
    draw string(dx,dy), mystring
end sub

dim as circle A
'option 1
A.radius=50
A.cx=400
A.cy=300
a.colour=6

dim as circle B
'option 2
with B
    .radius=80
    .cx=600
    .cy=300
    .colour=2
end with

screen 19

A.show
B.show

sleep
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by BasicCoder2 »

Trinity wrote: (and again remember I did not come from QB , I come from TI ExtB)
Googled the TI BASIC out of curiosity. I see it also had sprite commands. With regards to the original topic of the post I hadn't realized that LOCATE included anything about the cursor not having ever felt the need to look it up. I used QBASIC a long time ago and didn't remember anything about the cursor being involved. You may have an advantage over me due to having to look it all up you will know stuff I don't know!! And you are learning OOP from some very talented programmers. OOP is something the earlier FreeBasic didn't have when I first began using FreeBasic.
.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: ScreenRes & Cursor problem-What did I miss ? [EXPLAINED]

Post by grindstone »

@Trinity: fxm is right. You should strictly prevent using keywords as procedure- or variable names. If you can't find a meaningful different name use a leading or following underline (e.g. "_draw").

And now that you know what's about the dot I would recommend to you to stop dealing with OOP and TYPEs for now until you learned enough about the "plain" statements to write simple programs by yourself.
Post Reply