• Please be sure to read the rules and adhere to them. Some banned members have complained that they are not spammers. But they spammed us. Some even tried to redirect our members to other forums. Duh. Be smart. Read the rules and adhere to them and we will all get along just fine. Cheers. :beer: Link to the rules: https://www.forumsforums.com/threads/forum-rules-info.2974/

Any programmers on here?

tsaw

New member
I used to program on the Amiga computer, but they went out of business. Then I got a PC with Win 3.1 Sheesh... had to start all over again. I wrote a Amiga program called Deluxe Video Poker that was published in the magazine Amiga World around 1992. I finally decided to get back into programming! I'm taking my code for the Amiga and converting into Liberty Basic for Windows.

Here is what I wrote so far:

Code:
' Deluxe Video Poker 2011


'make window, start game
    nomainwin
    WindowWidth = 560 ' a window 560 across
    WindowHeight = 535 ' 535 tall
'center the new window on the screen
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

'load cards into memory so you can display them later

loadbmp "bg", "Cards\b1fv.bmp"      ' back of card

' load the Clubs
   loadbmp "ac", "Cards\c1.bmp"
   loadbmp "2c", "Cards\c2.bmp"
   loadbmp "3c", "Cards\c3.bmp"
   loadbmp "4c", "Cards\c4.bmp"
   loadbmp "5c", "Cards\c5.bmp"
   loadbmp "6c", "Cards\c6.bmp"
   loadbmp "7c", "Cards\c7.bmp"
   loadbmp "8c", "Cards\c8.bmp"
   loadbmp "9c", "Cards\c9.bmp"
   loadbmp "10c", "Cards\c10.bmp"
   loadbmp "jc", "Cards\cj.bmp"
   loadbmp "qc", "Cards\cq.bmp"
   loadbmp "kc", "Cards\ck.bmp"

'load the Diamonds
   loadbmp "ad", "Cards\d1.bmp"
   loadbmp "2d", "Cards\d2.bmp"
   loadbmp "3d", "Cards\d3.bmp"
   loadbmp "4d", "Cards\d4.bmp"
   loadbmp "5d", "Cards\d5.bmp"
   loadbmp "6d", "Cards\d6.bmp"
   loadbmp "7d", "Cards\d7.bmp"
   loadbmp "8d", "Cards\d8.bmp"
   loadbmp "9d", "Cards\d9.bmp"
   loadbmp "10d", "Cards\d10.bmp"
   loadbmp "jd", "Cards\dj.bmp"
   loadbmp "qd", "Cards\dq.bmp"
   loadbmp "kd", "Cards\dk.bmp"

'load the Hearts
   loadbmp "ah", "Cards\h1.bmp"
   loadbmp "2h", "Cards\h2.bmp"
   loadbmp "3h", "Cards\h3.bmp"
   loadbmp "4h", "Cards\h4.bmp"
   loadbmp "5h", "Cards\h5.bmp"
   loadbmp "6h", "Cards\h6.bmp"
   loadbmp "7h", "Cards\h7.bmp"
   loadbmp "8h", "Cards\h8.bmp"
   loadbmp "9h", "Cards\h9.bmp"
   loadbmp "10h", "Cards\h10.bmp"
   loadbmp "jh", "Cards\hj.bmp"
   loadbmp "qh", "Cards\hq.bmp"
   loadbmp "kh", "Cards\hk.bmp"

'load the Spades
   loadbmp "as", "Cards\s1.bmp"
   loadbmp "2s", "Cards\s2.bmp"
   loadbmp "3s", "Cards\s3.bmp"
   loadbmp "4s", "Cards\s4.bmp"
   loadbmp "5s", "Cards\s5.bmp"
   loadbmp "6s", "Cards\s6.bmp"
   loadbmp "7s", "Cards\s7.bmp"
   loadbmp "8s", "Cards\s8.bmp"
   loadbmp "9s", "Cards\s9.bmp"
   loadbmp "10s", "Cards\s10.bmp"
   loadbmp "js", "Cards\sj.bmp"
   loadbmp "qs", "Cards\sq.bmp"
   loadbmp "ks", "Cards\sk.bmp"


'set variable values used in the game
betamount=1 ' default bet value at start of game
dim deck(52) 'the array that holds the cards


' draw the graphicboxes across the screen
    graphicbox #main.card1, 56, 100, 75, 100 'card 1
    graphicbox #main.card2, 141, 100, 75, 100 'card 2
    graphicbox #main.card3, 226, 100, 75, 100 'card 3
    graphicbox #main.card4, 311, 100, 75, 100 'card 4
    graphicbox #main.card5, 396, 100, 75, 100 'card 5
    'graphicbox #main.graph6, 375, 1, 165, 65 ADD ANOTHER GRAPHICS BOX FOR PAYOUTS???


' draw the buttons
    button #main.button1,"Deal",[deal], UL, 225, 257,  80,  35
    button #main.button2,"Exit",[quit], UL, 465, 462,  70,  35
    button #main.button3,"Bet",[bet], UL, 235, 462,  75,  35
    button #main.button4,"Save",[save], UL, 465, 417,  70,  40






' open the graphics window
    open "Deluxe Video Poker 2011 Began on 1-13-11" for graphics_nsb_nf as #main

'show 5 cards face down
    print #main.card1, "down; drawbmp bg 1 1"
    print #main.card2, "down; drawbmp bg 1 1"
    print #main.card3, "down; drawbmp bg 1 1"
    print #main.card4, "down; drawbmp bg 1 1"
    print #main.card5, "down; drawbmp bg 1 1"


    print #main, "trapclose [quit]" 'if the x is clicked quit
    print #main, "when characterInput [quit]" 'for getting out of an enless loop - quit program when a key is hit
    print #main, "when leftButtonMove [displaymouse]"' take out later just for info

print #main.card1, "when leftButtonDown [card1clicked]"
print #main.card2, "when leftButtonDown [card2clicked]"
print #main.card3, "when leftButtonDown [card3clicked]"
print #main.card4, "when leftButtonDown [card4clicked]"
print #main.card5, "when leftButtonDown [card5clicked]"

     print #main, "place 260 450;font arial 0 20;color black;\$ ";betamount
     print #main, "place 30 16;font arial 0 20;color black;\Value of a = " 'a test routine

     print #main, "place 200 25;font arial 0 20;color red;\Deluxe Video Poker "
' done setting up the page----------------------------------




' the main loop
[main]
      wait' sit here and wait for a valid mouse click
' ------------------------------------------------------



'---------------------------------------- begin actions based on mouse clicks
[deal]
'for p= 1 to 500 'test used for the fun of seeing high speed dealing
dealclicked=1'the deal button was clicked

      gosub [dealcard]' uses the random number generator to pick a card - dealtcard is random

      gosub [whatcard] 'every card is assigned a number -
                       ' this sub takes the variable dealtcard and makes card$ the graphic to display
                       'if deltcard=1 then card$="ac"


      gosub [drawcard1]'display card 1

      gosub [dealcard]' uses the random number generator to pick a card - dealtcard is random

      gosub [whatcard] 'every card is assigned a number -
                       ' this sub takes the variable dealtcard and makes card$ the graphic to display
                       'if deltcard=1 then card$="ac"

      gosub [drawcard2]'display card 2
      gosub [dealcard]' uses the random number generator to pick a card - dealtcard is random

      gosub [whatcard] 'every card is assigned a number -
                       ' this sub takes the variable dealtcard and makes card$ the graphic to display
                        'if deltcard=1 then card$="ac"
      gosub [drawcard3]'display card 3


      gosub [dealcard]' uses the random number generator to pick a card - dealtcard is random

      gosub [whatcard] 'every card is assigned a number -
                       ' this sub takes the variable dealtcard and makes card$ the graphic to display
                       'if deltcard=1 then card$="ac"

      gosub [drawcard4]'display card 4

      gosub [dealcard]' uses the random number generator to pick a card - dealtcard is random

      gosub [whatcard] 'every card is assigned a number -
                       ' this sub takes the variable dealtcard and makes card$ the graphic to display
                       'if deltcard=1 then card$="ac"

      gosub [drawcard5]'display card 5

 'all 5 random cards are shown




            'test code
            print #main, "place 30 16;font arial 0 20;color black;\xxxxxxxxxxxxxxxxxxxxxxx"

            print #main, "place 30 16;font arial 0 20;color black;\Value of deltcard = ";deltcard
            'end test code

'next p
wait

'--------------------------------------------------------------------------------
[bet]'bet button clicked

     betamount=betamount +1
        If betamount>5 then betamount=1
     Print #main, "place 260 450;font arial 0 20;color black;\$  ";betamount
wait
'-----------------------------------------------------------------------------------


'-----------------------------------------------------------------
[dealcard]'the random number generator at work pick a random card


          deltcard=int(rnd(1)*52) + 1
          used=deltcard
            if deck(deltcard)=used then [dealcard]
          deck(deltcard)=used
for a = 1 to 52
deck(a)=0
next

return
'-----------------------------------------------------



'--------------------------------------------------------------------------------
'turn the number picked at random into an image to be displayed in [drawcard1] etc
[whatcard]
    if deltcard=1 then card$="ac"
    if deltcard=2 then card$="2c"
    if deltcard=3 then card$="3c"
    if deltcard=4 then card$="4c"
    if deltcard=5 then card$="5c"
    if deltcard=6 then card$="6c"
    if deltcard=7 then card$="7c"
    if deltcard=8 then card$="8c"
    if deltcard=9 then card$="9c"
    if deltcard=10 then card$="10c"
    if deltcard=11 then card$="jc"
    if deltcard=12 then card$="qc"
    if deltcard=13 then card$="kc"

    if deltcard=14 then card$="ad"
    if deltcard=15 then card$="2d"
    if deltcard=16 then card$="3d"
    if deltcard=17 then card$="4d"
    if deltcard=18 then card$="5d"
    if deltcard=19 then card$="6d"
    if deltcard=20 then card$="7d"
    if deltcard=21 then card$="8d"
    if deltcard=22 then card$="9d"
    if deltcard=23 then card$="10d"
    if deltcard=24 then card$="jd"
    if deltcard=25 then card$="qd"
    if deltcard=26 then card$="kd"

    if deltcard=27 then card$="ah"
    if deltcard=28 then card$="2h"
    if deltcard=29 then card$="3h"
    if deltcard=30 then card$="4h"
    if deltcard=31 then card$="5h"
    if deltcard=32 then card$="6h"
    if deltcard=33 then card$="7h"
    if deltcard=34 then card$="8h"
    if deltcard=35 then card$="9h"
    if deltcard=36 then card$="10h"
    if deltcard=37 then card$="jh"
    if deltcard=38 then card$="qh"
    if deltcard=39 then card$="kh"

    if deltcard=40 then card$="as"
    if deltcard=41 then card$="2s"
    if deltcard=42 then card$="3s"
    if deltcard=43 then card$="4s"
    if deltcard=44 then card$="5s"
    if deltcard=45 then card$="6s"
    if deltcard=46 then card$="7s"
    if deltcard=47 then card$="8s"
    if deltcard=48 then card$="9s"
    if deltcard=49 then card$="10s"
    if deltcard=50 then card$="js"
    if deltcard=51 then card$="qs"
    if deltcard=52 then card$="ks"

 return

'-----------------------------------------------------------------------
'draw the cards picked from the random number generator-----------------

[drawcard1]'show the image of card 1
if cardclicked1=0 then'the card is unheld if cardclicked1=1 then it is held
            print #main.card1, "down; drawbmp ";card$; " 1 1"
            return
end if


[drawcard2]'show the image of car2
if cardclicked2=0 then'the card is unheld if cardclicked1=1 then it is held
            print #main.card2, "down; drawbmp ";card$; " 1 1"
            return
end if


[drawcard3]'show the image of card 3
if cardclicked3=0 then'the card is unheld if cardclicked1=1 then it is held
            print #main.card3, "down; drawbmp ";card$; " 1 1"
            return
end if

[drawcard4]'show the image of card 4
if cardclicked4=0 then'the card is unheld if cardclicked1=1 then it is held
            print #main.card4, "down; drawbmp ";card$; " 1 1"
            return
end if

[drawcard5]'show the image of card 5
if cardclicked5=0 then'the card is unheld if cardclicked1=1 then it is held
            print #main.card5, "down; drawbmp ";card$; " 1 1"
            return
            end if
'-------------------------------------------------------------------------------




[displaymouse]
'take this out later just for fun and learning

'print using("######.##", a)

print #main, "place 30 16;font arial 0 20;color black;\Value of a ="; MouseX; " "; MouseY

  wait



[card1clicked]

If cardclicked1=0 and dealclicked=1 then
                   playwave "cards\held.wav", async
                   print #main, "place 70 216;font arial 0 20;color black;\HELD";
                   cardclicked1=1



else

    if cardclicked1=1 and dealclicked=1 then
                      playwave "cards\unheld.wav", async
                      print #main, "place 70 216;font arial 0 20;color black;\ ";"        "
                      cardclicked1=0
   end if
end if
wait

[card2clicked]

If cardclicked2=0 and dealclicked=1  then
                    playwave "cards\held.wav", async
                    print #main, "place 155 216;font arial 0 20;color black;\HELD";
                    cardclicked2=1



else

    if cardclicked2=1 and dealclicked=1 then
                      playwave "cards\unheld.wav", async
                      print #main, "place 155 216;font arial 0 20;color black;\ ";"        "
                      cardclicked2=0
   end if
end if
wait


[card3clicked]

If cardclicked3=0 and dealclicked=1  then
                   playwave "cards\held.wav", async
                   print #main, "place 240 216;font arial 0 20;color black;\HELD";
                   cardclicked3=1



else

    if cardclicked3=1 and dealclicked=1 then
                      playwave "cards\unheld.wav", async
                      print #main, "place 240 216;font arial 0 20;color black;\ ";"        "
                      cardclicked3=0
   end if
end if
wait

[card4clicked]

If cardclicked4=0 and dealclicked=1  then
                   playwave "cards\held.wav", async
                   print #main, "place 325 216;font arial 0 20;color black;\HELD";
                   cardclicked4=1



else

    if cardclicked4=1 and dealclicked=1 then
                      playwave "cards\unheld.wav", async
                      print #main, "place 325 216;font arial 0 20;color black;\ ";"        "
                      cardclicked4=0
   end if
end if
wait

[card5clicked]

If cardclicked5=0 and dealclicked=1  then
                   playwave "cards\held.wav", async
                   print #main, "place 410 216;font arial 0 20;color black;\HELD";
                   cardclicked5=1



else

    if cardclicked5=1 and dealclicked=1 then
                      playwave "cards\unheld.wav", async
                      print #main, "place 410 216;font arial 0 20;color black;\ ";"        "
                      cardclicked5=0
   end if
end if
wait



'code snippets for later use ----------------------------------------

'enable  disable controls
'nomainwin

'  button #win.bttn, "Hello",[hello],UL,10,70
 ' checkbox #win.cbox, "Goodbye",[quit],[quit],10,160,120,24
'  menu #win, "&Main","&Enable",[doEnable],_
'      "&Disable",[doDisable],"E&xit",[quit]
'  open "Enable and Disable" for window as #win

'  wait

'  [quit] close #win:end

'  [doEnable]
'  #win.bttn "!Enable"
'  #win.cbox "Enable"
'  wait

'  [doDisable]
'  #win.bttn "!Disable"
'  #win.cbox "Disable"
  'wait

 ' [hello] wait





[save]   'Perform action for the button named 'save'
         for a = 1 to 10000 'just for fun and learning
             print #main, "place 30 16;font arial 0 20;color black;\Value of a =";a
         next a
    wait

[quit]
  ' confirm"You really want to quit?";quit$
   ' if quit$="no" goto [main]
    unloadbmp "bg"'unload the back of card

'unload the Clubs
   unloadbmp "ac"
   unloadbmp "2c"
   unloadbmp "3c"
   unloadbmp "4c"
   unloadbmp "5c"
   unloadbmp "6c"
   unloadbmp "7c"
   unloadbmp "8c"
   unloadbmp "9c"
   unloadbmp "10c"
   unloadbmp "jc"
   unloadbmp "qc"
   unloadbmp "kc"

'unload the Diamonds
   unloadbmp "ad"
   unloadbmp "2d"
   unloadbmp "3d"
   unloadbmp "4d"
   unloadbmp "5d"
   unloadbmp "6d"
   unloadbmp "7d"
   unloadbmp "8d"
   unloadbmp "9d"
   unloadbmp "10d"
   unloadbmp "jd"
   unloadbmp "qd"
   unloadbmp "kd"

'unload the Hearts
   unloadbmp "ah"
   unloadbmp "2h"
   unloadbmp "3h"
   unloadbmp "4h"
   unloadbmp "5h"
   unloadbmp "6h"
   unloadbmp "7h"
   unloadbmp "8h"
   unloadbmp "9h"
   unloadbmp "10h"
   unloadbmp "jh"
   unloadbmp "qh"
   unloadbmp "kh"

'unload the Spades
   unloadbmp "as"
   unloadbmp "2s"
   unloadbmp "3s"
   unloadbmp "4s"
   unloadbmp "5s"
   unloadbmp "6s"
   unloadbmp "7s"
   unloadbmp "8s"
   unloadbmp "9s"
   unloadbmp "10s"
   unloadbmp "js"
   unloadbmp "qs"
   unloadbmp "ks"

    close #main'close window
    end


[zerovariables]'a gosub to begin a new hand

dealclicked=0

cardclicked1=0
cardclicked2=0
cardclicked3=0
cardclicked4=0
cardclicked5=0

return
 
Yes. Full time programmer.

Before you get too far into that language 9I have never heard of it), I would suggest taking a look at Visual Studio Express from Microsoft. You have your choice of languages, with the most common being VB.Net or C#. I would recommend C#.

http://www.microsoft.com/express/Downloads/#2010-Visual-CS

Thanks for the suggestion. I tried VB years ago, and it just didn't make any sense. The goofy syntax - files scattered all over the place. I like a language that is simple and all the code is on a single page. And most of all LOGICAL.
I also tried the new Visual studio from MS. YUCK . I found nothing to like.

While MS's .NET offering has rapid form development so does this language.
Just drag a windows function onto a work area, and it generates all the code.

To me in a much more user friendly way.
 
basic years ago no computer code lately
but lots of plc and hmi programs but mostly maintenance and T/S now
I wrote a basic program for a Casio FX700 for hose flow for the fire co that I ran with the other engineers couldent figure how I could get the truck right on pressure in 40 or 50 seconds till I showed the the program in the computer.

tom
 
DaveNay,

Would you be interested in helping me solve some programming challenges?

Sure, no problem. Although I am not familiar with the syntax of that language, most everything should be pretty straight forward.
 
Sure, no problem. Although I am not familiar with the syntax of that language, most everything should be pretty straight forward.

Ok. What is the best way to simulate a card shuffle?
I've always used

[dealcard]

deltcard=int(rnd(1)*52) + 1
used=deltcard
if deck(deltcard)=used then [dealcard]
deck(deltcard)=used
return

What you end up with is a random card picked by the random number generator and stored in the variable deltcard. The variable deck(52) is declared earlier in the program. As you call this sub, you cant get the same card twice - because as each card is picked.. the variable used is set. If the same random card is picked twice then you go right back to the rutine - If deck(deltcard)=used then [dealcard]
 
Ok. What is the best way to simulate a card shuffle?
I've always used

[dealcard]

deltcard=int(rnd(1)*52) + 1
used=deltcard
if deck(deltcard)=used then [dealcard]
deck(deltcard)=used
return

What you end up with is a random card picked by the random number generator and stored in the variable deltcard. The variable deck(52) is declared earlier in the program. As you call this sub, you cant get the same card twice - because as each card is picked.. the variable used is set. If the same random card is picked twice then you go right back to the rutine - If deck(deltcard)=used then [dealcard]

While there is nothing technically wrong with that method, I don't see it being very efficient, and has the potential to run slower than Rusty on New Years Day.

The problem is, when you get down into the second half of the deck, the routine is going to start descending into recursion hell. Imagine you are trying to deal the very last card in the deck. The rnd() function will select a card, and then you check if it is used. If it is used, you call the routine again (this is called recursion). This is repeated an unknown number of times until the one remaining card is selected. Since this code can be called recursively an unknown number of times, it is possible for it to generate an out of memory error, and crash the application.

What you have created, is the real world equivalent of holding a deck of cards in your hand and then randomly picking a card from within the deck when it is time to deal. I would suggest you actually perform the equivalent of shuffling the deck, and then simply deal off the top.

The following is pseudo code, and does not compile:

Code:
' Create the deck of cards
dim deck(52)

' Fill the deck of cards with card values
for card = 1 to 52
    deck(card) = card
next card

' Shuffle the deck
for card = 52 to 2 step -1
   ' Pick a random card between 1 and the current card
   randomCard = int(rnd(1)*card) + 1

   ' If the randomly selected card is not the current card, then swap
   if not randomCard = card
      tempcard = deck(card)
      deck(card) = deck(randomCard)
      deck(randomCard) = tempcard
   end if
next card

' The deck is now shuffled, and each time a card is dealt, take the next available card from the array.  This can be tracked with a variable that maintains the current index.

' For the next game, call the for loop above again (there is no need to re-fill the array) and reset the tracking variable to 1.

What this will do is move the first random card to the end of the deck, then the next random card to the (end - 1), then (end -2), etc. The loop only goes down to 2, because when you are done with the second position, there is only one possible choice for the last card, so there is no need to process it.

This method will have several improvements, namely performance. Since the deck is shuffled all at once, as opposed to randomly selecting a card each time, this only has to be performed once per game. This will give the user a much better experience. Also, since the rnd() function is only called 51 times total, instead of potentially hundreds, it will be much faster. Lastly, by eliminating the recursion, the potential for crashing the application is also eliminated.
 
I don't understand a damn thing you guys are talking about, but I think it's cool you are talking about it! :thumb:
 
I used to program some in COBOL, UNIX, FORTH, ASCII, RPG and C++. C++ is a good language to program in.
 
I vote for C# if you are on Windows. Java is OK. I do a lot of web stuff these days so I seem to do a lot of JavaScript, PHP, and .NET (usually C#).

I really like Visual Studio as an IDE.
 
I vote for C# if you are on Windows. Java is OK. I do a lot of web stuff these days so I seem to do a lot of JavaScript, PHP, and .NET (usually C#).

I really like Visual Studio as an IDE.

Visual Studio 2010 with ReSharper, and C# rocks.
 
Since I'm a jack-of-all-trades hack, I never get to spend a ton of time in any one language. It seems I'll get a few .NET projects then a few PHP projects but nothing remains the same. The only constant is Javascript so I spend a lot of time with JQuery and just use the server-side stuff for the grunt work via ajax/json. I do a lot with databases too so MySQL and MS SQL get occasional attention too.

Occasionally, I get to do AppleScript which can be interesting. I've been thinking of doing some iPhone/Android apps so that will be new. It's kind of fun to tackle new things although I never seem to master anything. I'm sure Dave can run circles around me in C#. ;)
 
Well done. I like it a lot.:clap:
I'm impressed. Thanks buddy. I owe you a beer.
I'm just like you. I always want efficient code.
On the surface, mine is shorter written - but yours in practice takes hundreds of less cpu cycles.

While there is nothing technically wrong with that method, I don't see it being very efficient, and has the potential to run slower than Rusty on New Years Day.

The problem is, when you get down into the second half of the deck, the routine is going to start descending into recursion hell. Imagine you are trying to deal the very last card in the deck. The rnd() function will select a card, and then you check if it is used. If it is used, you call the routine again (this is called recursion). This is repeated an unknown number of times until the one remaining card is selected. Since this code can be called recursively an unknown number of times, it is possible for it to generate an out of memory error, and crash the application.

What you have created, is the real world equivalent of holding a deck of cards in your hand and then randomly picking a card from within the deck when it is time to deal. I would suggest you actually perform the equivalent of shuffling the deck, and then simply deal off the top.

The following is pseudo code, and does not compile:

Code:
' Create the deck of cards
dim deck(52)

' Fill the deck of cards with card values
for card = 1 to 52
    deck(card) = card
next card

' Shuffle the deck
for card = 52 to 2 step -1
   ' Pick a random card between 1 and the current card
   randomCard = int(rnd(1)*card) + 1

   ' If the randomly selected card is not the current card, then swap
   if not randomCard = card
      tempcard = deck(card)
      deck(card) = deck(randomCard)
      deck(randomCard) = tempcard
   end if
next card

' The deck is now shuffled, and each time a card is dealt, take the next available card from the array.  This can be tracked with a variable that maintains the current index.

' For the next game, call the for loop above again (there is no need to re-fill the array) and reset the tracking variable to 1.
What this will do is move the first random card to the end of the deck, then the next random card to the (end - 1), then (end -2), etc. The loop only goes down to 2, because when you are done with the second position, there is only one possible choice for the last card, so there is no need to process it.

This method will have several improvements, namely performance. Since the deck is shuffled all at once, as opposed to randomly selecting a card each time, this only has to be performed once per game. This will give the user a much better experience. Also, since the rnd() function is only called 51 times total, instead of potentially hundreds, it will be much faster. Lastly, by eliminating the recursion, the potential for crashing the application is also eliminated.
 
WOW!!! Check this out!
talk about a stupid error in programming logic:

I have this in my program - it works 100%:

Code:
[drawcard4]'show the image of card 4
                 if cardclicked4=0 then  'the card is unheld if cardclicked1=1 then it is held
            print #main.card4, "down; drawbmp ";card$; " 1 1"
            return
end if
The ERROR is that I said RETURN BEFORE end if!

The correct way to write that is this:

Code:
[drawcard4]'show the image of card 1
if cardclicked1=0 then'the card is unheld if cardclicked1=1 then it is held
            print #main.card1, "down; drawbmp ";card$; " 1 1"

end if
            return
You will notice that AFTER the conditional IF is FINISHED - then I return to where I called it.
RATHER than in the middle.

Simple and logical.
 
Returning from inside an if block is perfectly acceptable.

Not on my planet:yum::yum::yum:

I've spent 4 hours finding that error.
Maybe in C you can get away with it.
In Liberty Basic it caused ALL kinds of unpredictable results.
Even the debugger showed the correct variable values.. but the program did not work as expected.

:tiphat:

I think the interpreter that I'm using isn't smart enough to reconcile a return from within a if block. ? I think that is so. In that case, I have to be VERY careful from now on. Otherwise I'll hit a wall of problems - and never figure out what is wrong.
 
Not on my planet:yum::yum::yum:

Then you need to find a new planet to live on. :unsure:

I've spent 4 hours finding that error.
Maybe in C you can get away with it.
In Liberty Basic it caused ALL kinds of unpredictable results.
Even the debugger showed the correct variable values.. but the program did not work as expected.

:tiphat:

I think the interpreter that I'm using isn't smart enough to reconcile a return from within a if block. ? I think that is so. In that case, I have to be VERY careful from now on. Otherwise I'll hit a wall of problems - and never figure out what is wrong.

EVERY modern language that I am familiar with allows a return from within a conditional block. I think perhaps one of the older languages (COBOL, FORTRAN?) has restrictions on the number and location of the return, but I am not familiar with the details.

If this is really the case with Liberty Basic, I would voice another suggestion for switching to a more well known language before you start to learn other bad habits from a language that is not fully functional.
 
Then you need to find a new planet to live on. :unsure:



EVERY modern language that I am familiar with allows a return from within a conditional block. I think perhaps one of the older languages (COBOL, FORTRAN?) has restrictions on the number and location of the return, but I am not familiar with the details.

If this is really the case with Liberty Basic, I would voice another suggestion for switching to a more well known language before you start to learn other bad habits from a language that is not fully functional.

I appreciate talking with you about programming. But I wonder if you understood what I was talking about.
Of course LB can return from within a conditional block. You just have to finish the condition.

Take this sample code:

a=x
b=y

gosub [dosomething]

more stuff to do...

[dosomething]

If a+b=3 then
print;(a+b)
this is where return should not be (like i had it)
End if
Return

If someothercondition then
dosomething
this is where return should not be (like i had it)
Endif
Return
<---- goes here

Now you see it?:unsure:
 
Now you see it?:unsure:

I see it just fine, and I saw it just fine when I replied earlier.

Everywhere that you say "this is where return should not be (like i had it)", you are not correct. It is perfectly acceptable to have the return statement at that position in the code (at least it is on all languages I am familiar with).
 
I see it just fine, and I saw it just fine when I replied earlier.

Everywhere that you say "this is where return should not be (like i had it)", you are not correct. It is perfectly acceptable to have the return statement at that position in the code (at least it is on all languages I am familiar with).

Yea i see what YOU are saying just fine now:hammer:
Bear with me on this ok? I'm leaning.:clap:
 
I agree with Dave. In my programming there are a lot of times that I'm in the middle of something and based on a condition I'll return. Heck, even in COBOL when I used to do that, it was OK to Go to Exit. I've done COBOL, CICS, VB, C++, RPG, C#, VB.NET, and a little Javascript.
 
Dave is right. I was wrong for the first time ever:hammer: :whistling: tsawwrong=-1 But as was said: You can return from an if then block in a subroutine no problem. I was mistaken. I'm making some use of that. as in:




[drawcreditnumbers]' max of 9 billion!
cash$ = str$(inhand)
#main "drawbmp n";mid$(cash$,1,1);" 101 264":If len(cash$)=1 then return
#main "drawbmp n";mid$(cash$,2,1);" 116 264":If len(cash$)=2 then return
#main "drawbmp n";mid$(cash$,3,1);" 131 264":If len(cash$)=3 then return
#main "drawbmp n";mid$(cash$,4,1);" 146 264":If len(cash$)=4 then return
#main "drawbmp n";mid$(cash$,5,1);" 161 264":If len(cash$)=5 then return
#main "drawbmp n";mid$(cash$,6,1);" 176 264":If len(cash$)=6 then return
#main "drawbmp n";mid$(cash$,7,1);" 191 264":If len(cash$)=7 then return
#main "drawbmp n";mid$(cash$,8,1);" 206 264":If len(cash$)=8 then return
#main "drawbmp n";mid$(cash$,9,1);" 221 264":If len(cash$)=9 then return
#main "drawbmp n";mid$(cash$,10,1);" 236 264":If len(cash$)=10 then return
return' needed just in case more than 9 billion credits (or if len(cash$)=11 COULD ADD
'another line and allow 99 billion credits?!!
 
Top