Liberty BASIC Community Forum
« Graphicbox code reduction ... HELP!!! »

Welcome Guest. Please Login or Register.
May 22nd, 2017, 10:33am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 2 3 4  Notify Send Topic Print
 veryhotthread  Author  Topic: Graphicbox code reduction ... HELP!!!  (Read 1086 times)
BeeTrap
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 5
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #15 on: Mar 15th, 2017, 08:38am »

Hello Turtleman
Please do keep us updated. JohnnyD's code example solved one problem that I have been having. I finally used the "Handle Variables" idea in it to get a variable within the name or "handle" of some listboxes. NOW I need to get a variable within the name of some arrays. Your code and/or solutions may just help me. Thanks.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5281
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #16 on: Mar 15th, 2017, 09:00am »

That would probably bee a multi dimensioned array()

array(var1,var2)
User IP Logged

BeeTrap
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 5
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #17 on: Mar 15th, 2017, 10:29am »

Thanks Rod, but....
more like this
var1 = 12
List.var1.$(var2) ' for a one-dimension string array

or
var1$ = "12"
List.var1$.$(var2)
or
"List" + var1$ + "$"(var2)

Such works on windows and textboxes, but I have yet to find this for an Array NAME or HANDLE.

LATER..........
OK, yes, a two-dimension array would work, just dawned on me like a stack of bricks....DUH!! It would require a big rewrite of the program, but isn't that part of the fun.
P.S. I appreciate the "bee" in your response, did notice!
Thanks!
« Last Edit: Mar 15th, 2017, 11:42am by BeeTrap » User IP Logged

Turtleman
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 173
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #18 on: Mar 16th, 2017, 10:18am »

I can't begin to describe how confused and frustrated I've become trying to get this "little" snippet of a program to work. So here's a link to a partial screenshot of the section that's causing all the grief: http://tiny.cc/r9ovjy

The Bet column for each row is working fine, so that's not an issue. For the W column, a right mouse click on a block increments and displays a number from 1 to 10, while a left mouse click on a block decrements its number. (The number in each block controls other functions.)

The L column is the same as the W column, which may expand into 2 or more additional columns. Likewise, the number of rows will probably double, and the range of block numbers will always equal the number of rows.

Actually, all but the color selection portion is already working! What I'm trying to do now is to selectively control the background color for any and all of the blocks in the W column the other column(s) do the same thing.) For better visibility, if the background color is dark, then the displayed digit should be white. And if the background color is light, then the number should be black. Only 4-6 defined colors are anticipated being used, and will be chosen by external events. Only a single background color per column will be displayed at any one time. (The block numbers control other functions.)

Amazingly, everything is working except for the ability to change colors. Other than the single designated background color, the rest of the column will be white or some light shade of green or red.

As always, any suggestions and examples would be greatly appreciated!!!
User IP Logged

Turtleman
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 173
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #19 on: Mar 17th, 2017, 2:12pm »

Quickie question

I'm having a problem using JohnnyD's color example: "if color=a-1 then #h$,"down; fill "colour$(a)+"; backcolor "+colour$(a)"

This works: if color = a-1 then #h$, "down; fill red; color black; backcolor red"

However, if I substitute: if color = a-1 then #h$, "down; fill "colour$(a)+"; color black; backcolor red" I get a popup message "colour$(a) is not a valid color"

In other words, trying to substitute colour$(a) in place of red, after defining colour$(a) = "red" doesn't work. Likewise, trying variations using color in place of colour and leaving off the + or quotes makes no difference.

If colours$(a) = red, why can't it be used in place of red?

What I am doing wrong? Thanks!
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1637
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #20 on: Mar 17th, 2017, 3:55pm »

Quote:
I get a popup message "colour$(a) is not a valid color"


That means #h$ actually got "colour$(a) " instead of "";colour$(a)
- probably misplaced (") or missing (;)

Replace #h$ with print and see in a mainwin what you actually printing to #h$.
« Last Edit: Mar 17th, 2017, 3:55pm by tsh73 » User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
tenochtitlanuk
Board Moderator

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1150
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #21 on: Mar 17th, 2017, 4:32pm »

What we are saying is shown by this short example- see the mainwindow showing the correctly-formed graphic commands.

NB It is easier for you and us if you put code, as here, in [ code] [ /code] markers.
Code:

    UpperLeftX   =  10
    UpperLeftY   =  10
    WindowWidth  = 400
    WindowHeight = 400

    graphicbox #w.gb1,   20, 10, 360, 300

    dim colour$( 12)

    open "Colour demo" for window as #w

    #w     "trapclose quit"
    #w.gb1 "down ; size 4"

    for i =0 to 11  '   invent 12 random colours indexed 0 to 11
        colour$( i) =str$( int( 256 *rnd( 1))) +" " +str$( int( 256 *rnd( 1))) +" " +str$( int( 256 *rnd( 1)))
    next i

    colour$( 5) ="red"  '   just to show use of pre-defined LB colours..

    for i =1 to 10
        #w.gb1 "color "+colour$( i +1)
        print  "color "+colour$( i +1)
        #w.gb1 "down; fill "; colour$( i); "; backcolor "+colour$( 11 -i)
        print  "down; fill "; colour$( i); "; backcolor "+colour$( 11 -i)
        #w.gb1 "home ; circlefilled 100"
        print  "home ; circlefilled 100": print
        timer 1000, [o]
        wait
      [o]
        timer 0
    next i

    wait

    sub quit h$
        close #h$
        end
    end sub
 

You can see my user defined colours being used for draw, fill and background.
User IP Logged

Turtleman
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 173
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #22 on: Mar 18th, 2017, 10:11am »

Quotes and semicolons in the right place make all the difference! The correct syntax is probably explained somewhere, but it's far from obvious or second nature to me. Likewise, I'm not sure what the + sign before colour$ is for; and in fact, the code doesn't work if it's included! I'm also uncertain how "if color = a 1" or other digit selects the row for the color designated by a, but the code is working! Honestly, I don't know what's worse: not understanding why code doesn't work or not understanding why it does. smiley

Now to duplicate the code for three more columns and try to reduce the amount of code for incrementing and decrementing the count. Currently, each column includes:

[IncreaseBetCounter1]
counter1 = counter1 + 1
if counter1 > max then counter1 = 1
if counter1 < 1 then counter1 = max
gosub [DrawField1]
wait
[DecreaseBetCounter1]
counter1 = counter1 - 1
if counter1 > max then counter1 = 1
if counter1 < 1 then counter1 = max
gosub [DrawField1]
wait

[IncreaseBetCounter2]
counter2 = counter2 + 1
if counter2 > max then counter2 = 1
if counter2 < 1 then counter2 = max
gosub [DrawField2]
wait
[DecreaseBetCounter2]
counter2 = counter2 - 1
if counter2 > max then counter2 = 1
if counter2 < 1 then counter2 = max
gosub [DrawField2]
wait

and so on. 10 rows of 4 columns like this will currently require 480 lines of what I'm guessing is a lot of redundant code. Hopefully, I'll be able to somehow substitute variables and reduce it to something more manageable. As Arnold says, "I'll be back!" Meanwhile, thanks for all the great help, it's most appreciated!!!
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5281
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #23 on: Mar 19th, 2017, 04:24am »

The ; and + symbol can both be used to concatenate strings. Both work, but you need to print your string if you get an error and that will show what you have wrong in the concatenation. You are aiming for a string built from variables that looks exactly like the literal string needed to draw the graphics.

Code:
a=1
colour$(a)="red"
print "down; fill red; color black; backcolor red"
print "down; fill ";colour$(a)+"; color black; backcolor red"
print "down; fill ";colour$(a);"; color black; backcolor red"
 


So you had a missing semicolon after "down; fill ", actually JohnnyD had a missing ; but debugging is part of the fun.
« Last Edit: Mar 19th, 2017, 04:27am by Rod » User IP Logged

Turtleman
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 173
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #24 on: Mar 19th, 2017, 04:44am »

Thanks Rod, I'm slowly (very slowly) catching on!

Meanwhile, I discovered that what I thought was working isn't doing what's needed. Namely, the code used for incrementing and decrementing the count in the graphicboxes works perfectly, while changing the count is only an infrequent setup. The color of the individual graphicboxes, however, is constantly changing, and so far I haven't been able to find a way of doing just that without repopulating the count.) Only one color will be active at a time and will revert to white (or some other light background) when deselected. Back to the drawing board!
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5281
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #25 on: Mar 19th, 2017, 05:36am »

Not sure I understand how your color decisioning works but here is some example code that manages forty boxes in one graphicbox. It increments and decrements the box value and changes the color according to the value of the box.

All in fifty lines of code!

Code:
dim bet(3,9)' 4 col 10 row value
    dim colour$(5)

    colour$(1)="green"
    colour$(2)="red"
    colour$(3)="blue"
    colour$(4)="yellow"
    colour$(0)="white"

    nomainwin
    WindowWidth = 600
    WindowHeight = 700
    graphicbox #1.gb 200,10,226,555
    open "Bet Array" for window as #1
    #1 "trapclose [quit]"

    'draw our background and flush it
    #1.gb "down ; fill blue"
    #1.gb "backcolor white"
    for c= 0 to 9
        for r= 0 to 3
            #1.gb "place ";r*50+r*5+5;" ";c*50+c*5+5;" ; boxfilled ";r*50+r*5+55;" ";c*50+c*5+55
        next
    next
    #1.gb "flush bak"

    'start looking for mouse input
    #1.gb "when leftButtonDown [checkinc]"
    #1.gb "when rightButtonDown [checkdec]"
    wait

    [checkinc]
    'establish what square the mouse was on
    r=int(MouseX/55) '0-3
    c=int(MouseY/55) '0-9
    'update "counter" array value
    box(r,c)=box(r,c)+1
    gosub [update]
    wait

    [checkdec]
    'establish what square the mouse was on
    r=int(MouseX/55) '0-3
    c=int(MouseY/55) '0-9
    'update "counter" array value
    box(r,c)=box(r,c)-1
    gosub [update]
    wait

    [update]
    #1.gb "cls ; fill blue"
    for c= 0 to 9
        for r= 0 to 3
            'set the box background color of choice
            if box(r,c)>0 then
                #1.gb "backcolor ";colour$(int(box(r,c)/10))
                else
                #1.gb "backcolor white"
            end if
            'redraw box background
            #1.gb "place ";r*50+r*5+5;" ";c*50+c*5+5;" ; boxfilled ";r*50+r*5+55;" ";c*50+c*5+55
            'redraw bit(r,c) value "counter" from array
            #1.gb "place ";r*50+r*5+25;" ";c*50+c*5+45;";\";box(r,c)
        next
    next
    #1.gb "flush"
    return


    [quit]
    close #1
    end

 
User IP Logged

Turtleman
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 173
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #26 on: Mar 19th, 2017, 05:54am »

Thanks Rod; that's a pretty neat program. However, in the example, the color of a particular graphicbox changes according to the count; whereas in my application, I need to be able to change the color of any of the graphicboxes regardless of the count. (The count is only used to control other functions. The color indicates the count that is being used, which can be in any of the graphicboxes.)

Back soon. As is often the case when I try to work on something, another computer problem rears its ugly head!
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5281
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #27 on: Mar 19th, 2017, 07:10am »

Even easier then. Just have another array holding the color value. Change the col(r,c) color value to whatever you want and gosub [update].

Code:
 dim bet(3,9)' 4 col 10 row value
    dim col(3,9)' 4 col 10 row color 0-5

    colour$(1)="green"
    colour$(2)="red"
    colour$(3)="blue"
    colour$(4)="yellow"
    colour$(0)="white"

    'set some random colors
    for n= 1 to 20
        col(int(rnd(0)*4),int(rnd(0)*10))=int(rnd(0)*5)
    next

    nomainwin
    WindowWidth = 600
    WindowHeight = 700
    graphicbox #1.gb 200,10,226,555
    open "Bet Array" for window as #1
    #1 "trapclose [quit]"

    #1.gb "down"
    gosub [update]

    'start looking for mouse input
    #1.gb "when leftButtonDown [checkinc]"
    #1.gb "when rightButtonDown [checkdec]"
    wait

    [checkinc]
    'establish what square the mouse was on
    r=int(MouseX/55) '0-3
    c=int(MouseY/55) '0-9
    'update "counter" array value
    box(r,c)=box(r,c)+1
    gosub [update]
    wait

    [checkdec]
    'establish what square the mouse was on
    r=int(MouseX/55) '0-3
    c=int(MouseY/55) '0-9
    'update "counter" array value
    box(r,c)=box(r,c)-1
    gosub [update]
    wait

    [update]
    #1.gb "cls ; fill blue"
    for c= 0 to 9
        for r= 0 to 3
            'set the box background color from col(r,c)
            #1.gb "backcolor ";colour$(col(r,c))
            'redraw box background
            #1.gb "place ";r*50+r*5+5;" ";c*50+c*5+5;" ; boxfilled ";r*50+r*5+55;" ";c*50+c*5+55
            'redraw bit(r,c) value "counter" from array
            #1.gb "place ";r*50+r*5+25;" ";c*50+c*5+45;";\";box(r,c)
        next
    next
    #1.gb "flush"
    return


    [quit]
    close #1
    end


 
User IP Logged

Turtleman
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 173
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #28 on: Mar 19th, 2017, 07:26am »

Thanks again. I'll have to spend some time studying the code and just now got the computer back on. (I don't think Windows 10 should take now be taking over 10 minutes to boot! LOL)

Changing colors of any (or all blocks) needs to be accomplished with an instruction NOT requiring the mouse to identify the block. Therefore, a name (or coordinate) has to be assigned to each graphicbox so its color can be altered. Maybe your example can be modified to do that; but like I said, I just got back on line a few minutes ago.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5281
xx Re: Graphicbox code reduction ... HELP!!!
« Reply #29 on: Mar 19th, 2017, 10:30am »

Yep the name of a graphic box is box(r,c), the color is set by changing col(r,c), you see the change by calling [update].

So you don't need the mouse to initiate the change, wherever in your code you want reset all or one of the col(r,c) array elements and call [update] to see your box change color and retain its old box(r,c) value.

Arrays are useful things.
User IP Logged

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

Rules|Home|Help|Search|Recent Posts|Notification

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