BBC BASIC
« Re: Unlimited button creation BUTTONZ-mygraphics »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 6:02pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Re: Unlimited button creation BUTTONZ-mygraphics  (Read 547 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
cheesy Re: Unlimited button creation BUTTONZ-mygraphics
« Thread started on: Nov 14th, 2016, 08:36am »

on Nov 13th, 2016, 10:57pm, michael wrote:
A breakthough!

As it stands your listed code has a nasty problem - it uses 100% CPU! I know it's only a demo rather than a full program, but my poor laptop battery and fan don't know that. Add a WAIT in the main loop (try to get into the habit of doing this without thinking):

Code:
      REPEAT
        a$= FNbuttonz(300,300,"Limitless buttons and no need for complexity !!")
        a$= FNbuttonz(100,100,"This is a button TEST")
        IF a$<>"" THEN PROCpr(200,200,"you clicked on "+a$+"","255,255,255")
        WAIT 2
      UNTIL FALSE 

Also, you describe the rest of the program as a 'library', but it doesn't adhere to recommendations for a shared library such as not modifying global variables. You can find the guidelines at the wiki here.

Richard.
« Last Edit: Nov 14th, 2016, 09:40am by Richard Russell » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
cheesy Re: Unlimited button creation BUTTONZ-mygraphics
« Reply #1 on: Nov 14th, 2016, 1:20pm »

on Nov 14th, 2016, 12:11pm, michael wrote:
To solve the global issue ... I could just make special globals that a user is extremely unlikely to use.

The wiki article to which I linked suggests some solutions:
  • Pass an opaque structure as a parameter to all the functions needing to share variables. This is probably the most 'elegant' solution, but it is an overhead both for your library and for the user.

  • Leverage one of the techniques described at the Sharing PRIVATE variables article at the wiki.

  • As you suggest, use globals with names that are very unlikely to be used in the main program. If you want to be ultra safe, incorporate a GUID in the name. Another good approach is to incorporate the library name after an @ symbol, such as globalvar@mylibrary.
Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls