Author Topic: Can't get my console class to work  (Read 17579 times)

0 Members and 3 Guests are viewing this topic.

kryton9

  • Guest
Can't get my console class to work
« on: July 03, 2011, 01:53:35 AM »
Having some problems still, but it is getting there:
Problems noted in source code files:
TestConsoleC01.o2bas and TestConsoleC02.o2bas

Attached is a 7zip file projects.7z: projects/kent/ 8 files

8 files:
BaseUtils.inc
ConsoleC.inc
TestConsoleC01.o2bas through TestConsoleC06.o2bas

thanks in advance!

[attachment deleted by admin]
« Last Edit: July 10, 2011, 08:12:55 PM by kryton9 »

kryton9

  • Guest
Re: Can't get my console class to work
« Reply #1 on: July 03, 2011, 03:18:36 AM »
I got it figured out, but not the way it should be.

I had to manually call the constructor and to be safe I called the destructor.
Here is the working code.
Code: OxygenBasic
  1. include once "ConsoleC.inc"
  2. include once "BaseUtils.inc"
  3.  
  4. int i
  5. string s$
  6.  
  7.  
  8. ConsoleC c
  9. c.Constructor( "kent console test" )
  10.     For i = 1 to 5
  11.         c.Print "This is string "  str(i) crlf$
  12.     Next i
  13.  
  14.     c.Print "press any key"  crlf$
  15.     c.GetKey
  16.  
  17.     s$ = c.Input "enter data -> "
  18.     c.Print "Data = "  s$ crlf$
  19.  
  20.     c.Print "press any key"  crlf$
  21.     c.GetKey
  22. c.Destructor()

This is the way it should be, in my opinion. Where the constructor and destructor are called automatically.
Code: OxygenBasic
  1. include once "ConsoleC.inc"
  2. include once "BaseUtils.inc"
  3.  
  4. int i
  5. string s$
  6.  
  7.  
  8. ConsoleC c( "kent console test" )
  9.  
  10. For i = 1 to 5
  11.     c.Print "This is string "  str(i) crlf$
  12. Next i
  13.  
  14. c.Print "press any key"  crlf$
  15. c.GetKey
  16.  
  17. s$ = c.Input "enter data -> "
  18. c.Print "Data = "  s$ crlf$
  19.  
  20. c.Print "press any key"  crlf$
  21. c.GetKey
  22.  
« Last Edit: July 03, 2011, 03:40:57 AM by kryton9 »

kryton9

  • Guest
Re: Can't get my console class to work
« Reply #2 on: July 03, 2011, 03:50:57 AM »
This does work as I thought it should, but it is using dynamic memory where as the previous should be just using program memory and work.
Code: OxygenBasic
  1. include once "ConsoleC.inc"
  2. include once "BaseUtils.inc"
  3.  
  4. int i
  5. string s$
  6.  
  7.  
  8. new ConsoleC c "kent test console"  'using new so make sure to delete when finished
  9.  
  10. For i = 1 to 5
  11.     c.Print "This is string "  str(i) crlf$
  12. Next i
  13.  
  14. c.Print "press any key"  crlf$
  15. c.GetKey
  16.  
  17. s$ = c.Input "enter data -> "
  18. c.Print "Data = "  s$ crlf$
  19.  
  20. c.Print "press any key"  crlf$
  21. c.GetKey
  22. del c 'deleting

Charles Pegge

  • Guest
Re: Can't get my console class to work
« Reply #3 on: July 03, 2011, 01:13:09 PM »

Hi Kent,

Today the compiler is dismantled and I have the engine blocks out :)
I think there's another 16 hours of work to go before it is up and running again and I can disengage from the task. Doing some major mods for auto string/number conversions.

Will look at your code as soon as I can.

Charles

kryton9

  • Guest
Re: Can't get my console class to work
« Reply #4 on: July 03, 2011, 01:24:40 PM »
Good luck Charles with your core work. No need to rush on my code, I got it figured out. We can talk about the auto constructor call in non dynamic creations of an object later.

kryton9

  • Guest
Re: Can't get my console class to work
« Reply #5 on: July 03, 2011, 11:06:55 PM »
Here is a screenshot of the console class in action so far. Got some more things to add to it.
Here is the code for that output:
Code: OxygenBasic
  1. 'Last modified:
  2. '2011.07.04 02:50 KS
  3.  
  4. include once "ConsoleC.inc"
  5.  
  6. sys i
  7. string s$
  8.  
  9. new ConsoleC c "Window Console Title: TestConsoleC.o2bas"
  10.  
  11.     c.SetColor FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
  12.     s$ = c.GetTitle() crlf$
  13.     c.Print s$ crlf$ crlf$
  14.    
  15.     c.SetColor FOREGROUND_RED or FOREGROUND_BLUE or FOREGROUND_INTENSITY
  16.     s$ = c.Input "Enter data: "
  17.     c.SetColor DEFAULT_COLOR
  18.     c.Print crlf$ "Data entered: " s$ crlf$  crlf$
  19.  
  20.     c.SetColor  F_DARK_GREEN   : c.Print "DARK_GREEN"    crlf$
  21.     c.SetColor  F_GREEN        : c.Print "GREEN"         crlf$        
  22.     c.SetColor  F_DARK_BLUE    : c.Print "DARK_BLUE"     crlf$    
  23.     c.SetColor  F_BLUE         : c.Print "BLUE"          crlf$        
  24.     c.SetColor  F_DARK_RED     : c.Print "DARK_RED"      crlf$    
  25.     c.SetColor  F_RED          : c.Print "RED"           crlf$          
  26.     c.SetColor  F_DARK_YELLOW  : c.Print "DARK_YELLOW"   crlf$  
  27.     c.SetColor  F_YELLOW       : c.Print "YELLOW"        crlf$      
  28.     c.SetColor  F_DARK_PURPLE  : c.Print "DARK_PURPLE"   crlf$
  29.     c.SetColor  F_PURPLE       : c.Print "PURPLE"        crlf$      
  30.     c.SetColor  F_DARK_CYAN    : c.Print "DARK_CYAN"     crlf$    
  31.     c.SetColor  F_CYAN         : c.Print "CYAN"          crlf$
  32.     c.SetColor  F_DARK_GREY    : c.Print "DARK_GREY"     crlf$    
  33.     c.SetColor  F_GREY         : c.Print "GREY"          crlf$        
  34.     c.SetColor  F_WHITE        : c.Print "WHITE"         crlf$
  35.    
  36.     c.SetCPos 20, 30
  37.     'only B_DARK_GREEN will print at the cursor position
  38.    c.SetColor  B_DARK_GREEN   : c.Print "DARK_GREEN "   crlf$
  39.     c.SetColor  B_GREEN        : c.Print "GREEN      "   crlf$        
  40.     c.SetColor  B_DARK_BLUE    : c.Print "DARK_BLUE  "   crlf$    
  41.     c.SetColor  B_BLUE         : c.Print "BLUE       "   crlf$        
  42.     c.SetColor  B_DARK_RED     : c.Print "DARK_RED   "   crlf$    
  43.     c.SetColor  B_RED          : c.Print "RED        "   crlf$          
  44.     c.SetColor  B_DARK_YELLOW  : c.Print "DARK_YELLOW"   crlf$  
  45.     c.SetColor  B_YELLOW       : c.Print "YELLOW     "   crlf$      
  46.     c.SetColor  B_DARK_PURPLE  : c.Print "DARK_PURPLE"   crlf$
  47.     c.SetColor  B_PURPLE       : c.Print "PURPLE     "   crlf$      
  48.     c.SetColor  B_DARK_CYAN    : c.Print "DARK_CYAN  "   crlf$    
  49.     c.SetColor  B_CYAN         : c.Print "CYAN       "   crlf$
  50.     c.SetColor  B_DARK_GREY    : c.Print "DARK_GREY  "   crlf$    
  51.     c.SetColor  B_GREY         : c.Print "GREY       "   crlf$        
  52.     c.SetColor  B_WHITE        : c.Print "WHITE      "   crlf$
  53.    
  54.     c.SetColor DEFAULT_COLOR
  55.     c.Print crlf$ crlf$ crlf$
  56.     c.Print "Press a key to exit." crlf$
  57.     c.GetKey
  58. del c

[attachment deleted by admin]
« Last Edit: July 04, 2011, 02:20:32 AM by kryton9 »

kryton9

  • Guest
Re: Can't get my console class to work
« Reply #6 on: July 04, 2011, 02:15:39 AM »
I updated the first post Charles with my latest files. I am having problems with a function. I tried everything I could think of with pointer syntax to get it working and none of them worked for me.

Three areas to look.
ConsoleC.inc: sys GetConsoleScreenBufferInfo( sys hConsoleOutput, CONSOLE_SCREEN_BUFFER_INFO *lpConsoleScreenBufferInfo )
ConsoleC.inc: method GetSBI( CONSOLE_SCREEN_BUFFER_INFO aSBI ) as sys
TestConsoleC02.o2bas:CONSOLE_SCREEN_BUFFER_INFO aSBI and if c.GetSBI aSBI then

Hope your engine overall is going well!

Attachments in first post, thanks.

Charles Pegge

  • Guest
Re: Can't get my console class to work
« Reply #7 on: July 04, 2011, 11:09:07 PM »

Hi Kent,

A quick note about constructors and destructors:

Only dynamically defined objects automatically call constructor/destructor methods. The keywords new and del are actually macros:

Code: [Select]

def new %1 * %2 : @%2=?news sizeof %1 : %2.constructor

def  del %1.destructor : frees @%1 : @%1=0


Oxygen classes are naturally lazy. All objects, like basic variables are initialised to the null state but constructor and destructor methods are not assumed. This is advantageous for minor classes. I wanted to make classes as near to user-defined-types as possible.

Programmers are free to make their own macros for creating and initialising objects.

Charles

kryton9

  • Guest
Re: Can't get my console class to work
« Reply #8 on: July 05, 2011, 01:47:31 AM »
That's fine Charles. I just need to add that to the reference.

I still couldn't get that method above I wrote about to work.
« Last Edit: July 05, 2011, 03:07:33 AM by kryton9 »

Charles Pegge

  • Guest
Re: Can't get my console class to work
« Reply #9 on: July 05, 2011, 03:56:53 PM »

Kent,

I am still working on Oxygen core. This will have a more sophisticated autotype conversion. I persist on the grounds that what doesn't kill you makes you stronger! :)

I nearly have it working then I can release my focus.

Charles

kryton9

  • Guest
Re: Can't get my console class to work
« Reply #10 on: July 05, 2011, 04:53:44 PM »
Good luck Charles. I am sure it is a very tough job, glad you are getting stronger :)

Peter

  • Guest
Re: Can't get my console class to work
« Reply #11 on: July 06, 2011, 03:25:15 AM »
And the simpleness stays on the route.  :D

Charles Pegge

  • Guest
Re: Can't get my console class to work
« Reply #12 on: July 06, 2011, 03:36:48 AM »

Simpler I anticipate.

str() and val() are almost redundant.

Instead of performing numerology this will produce a proper total:

print "sum " 1 2 3 4 5 6 7

Most of the effort goes into ensuring it works with all variables, procedures and objects.

Charles


Peter

  • Guest
Re: Can't get my console class to work
« Reply #13 on: July 06, 2011, 04:43:29 AM »
Str(), Val()  and something else,  that was my apprehension !    :-[

Charles Pegge

  • Guest
Re: Can't get my console class to work
« Reply #14 on: July 06, 2011, 05:06:53 AM »

These functions will still be present. The changes make the compiler handle different types more intelligently. The main impact is on light-duty programming. It narrows the gap between compiling and scripting Basic.

Charles