|
Post by tailoredreaction on May 6, 2024 15:09:31 GMT
Hi All,
I have made a graphics word game, similar to word games found online like WORDLE. I want to know if it is possible to save the results, ie a player's score to WINDOWS clipboard to post the saved strings and/or variables at a site outside of the program itself? Ideally I'd like the game to "SHARE" a player's score, the date, and a string that states the name of the game I've created so that player can just paste their results to a site like Facebook, or Disqus.
I see that there is a command in Just Basic called < !copy > that seems like it might do the trick, but I have no idea how I would use this to copy the information I'd like to share.
Any ideas? Also, if this is the wrong track, does anyone know of a different path I can go to do what I have in mind?
Thanking you all in advance.
|
|
|
Post by tenochtitlanuk on May 6, 2024 19:13:38 GMT
If you move to JB's 'big brother' Liberty BASIC you get access to Windows API functions or external DLLs. It will cost you nothing to experiment with LB- but you get increasingly slow start up and a nag screen unless you pay for a licence. Money well spent I reckon... It is then easy to use current values of variables, or indeed copy them from a textbox/editor, and send them over the web to a server. The way I use is sending by ftp. Another program on the same or a different computer can then read them and process the data. I use an ordinary http call to get the data back. You'll also find on my site and at the LB Forum examples of using sendemail, which may be closer to what you want. You can find free servers online, and also cheap ones. Pay a bit more and you can have a web host like I use for my LB website at Diga Me! websiteAlternatively you could set up your own computer as a web server, keep it on 24/24, and worry about security. If you search my site for 'IOT' you'll find a page with working code- but I've NOT given the web address and password for obvious reasons.
|
|
|
Post by tsh73 on May 6, 2024 19:47:24 GMT
1) JB way uses auxiliary window to use COPY command
input "Enter some text to be put into clipboard";txt$
open "aux clip window" for text as #clipText #clipText txt$; #clipText "!selectall" #clipText "!copy" close #clipText
print "The text is now in clipboard, try to paste elsewhere" print "(JB mainwin does not accept pasted text inti INPUT, alas)"
2) command line way ises build-in Windows CLIP command
input "Enter some text to be put into clipboard";txt$
run "cmd.exe /c echo "+txt$+" | clip", hide
print "The text is now in clipboard, try to paste elsewhere" print "(JB mainwin does not accept pasted text inti INPUT, alas)"
|
|
|
Post by xxgeek on May 6, 2024 21:18:40 GMT
Sounds to me like you are using either a regular Window, or a graphics Window for a "graphics program".
Mainwin and input is not going to help if that is the case and nomainwin is being used.
Posting your code always helps to understand better what you are up to.
'this is just an example for you to work with and adapt to your code, and your variable names 'use what you need and toss the rest
nomainwin name$="WORDLE" 'name of the game myscore$ = "whatever YourScore is" 'date$() is a JB built in function that retrieves the date.
'first - create a hidden texteditor in YOUR window texteditor #1.textED, 0,0,0,0 'the zeros will keep it hidden since there is no length or width open "WORLDLE" for graphics as #1 'can call the window anything you like
'then you need to put what you want to copy into the texteditor 'let's assume your score is kept in a variable named myscore$ 'you want the name of the game, the date, and the score copied to clipboard 'You don't need to use print, but I add that word to avoid confusion
'One way to do it - formatted in one line print #1.textED, name$;" ";Date$();" ";myscore$
'another way - formatted in several lines 'uncomment the print lines to use 'print #1.textED name$ 'print #1.texED Date$() 'print #1.textED myscore$
'Ok, now the text is in the texteditor, but you can't see it, nor do you want to see it.. 'In order to use "!copy" you need to have something to copy, 'and you want ALL that's in the texteditor so:
print #1.textED "!selectall"
'now you can copy it to the clipboard print #1.textED "!copy"
'close the window in your program when needed close #1
'then clear the textbox making it ready for the next time #1.textED "!cls" Notice "Your Text is now in the Clipboard - Paste it somewhere" end
|
|
|
Post by tsh73 on May 7, 2024 18:11:24 GMT
Just recalled you can output text to PROMPT dialog it comes highlighted, so if user needs that he could just press Ctrl-C to copy Try this
textToBeCopied$ = "Just press Crtl-C and copy it" prompt "You can copy text below"; textToBeCopied$
|
|
|
Post by tailoredreaction on May 7, 2024 19:36:43 GMT
Just figuring out how to respond to a post.
|
|
|
Post by tailoredreaction on May 7, 2024 19:49:08 GMT
I have totally forgotten how to reply directly to a post here.
I tried xxgeek's method and it worked flawlessly. I see tsh's response and I am confident that would have worked as well. I was stuck with the !copy command I think because it said it "copies the selected text" and for the life of me I couldn't figure out how to "select text" to copy.
So thank you everyone. I am not sure if trying Liberty Basic is for me or that I will be hosting a server any time soon. But I will always keep this place in mind if/when I get stuck in the future.
I have a related question. I can copy/paste a .bmp file from a folder to a website like facebook. Where does Windows store the .bmp file from when I "copy" it and when I "paste" it? is that temporarily saved to the clipboard as well?
|
|
|
Post by xxgeek on May 8, 2024 19:10:42 GMT
Here is an example I have been working on.
It will create a .bmp file, a bat file, and then run the bat file. Then when it copies the .bmp to the clipboard it will give notice.
Keep in mind this code is taken from the test program I was working on and will NOT work on your PC as is.
It is an example to work with to be adapted to your own uses.
#1 "getbmp scr 80 0 415 430" bmpsave "scr", "visualScore.bmp" open "bmpclip.bat" for output as #clip #clip "powershell -command Add-Type -AssemblyName System.Windows.Forms; Add-Type -AssemblyName System.Drawing; [System.Windows.Forms.Clipboard]::SetImage([System.Drawing.Image]::FromFile('%1'))" close #clip run "cmd.exe /c bmpclip.bat visualScore.bmp",hide notice "Ready to paste, from the Clipboard"
|
|
|
Post by xxgeek on May 8, 2024 21:22:55 GMT
Here is a working example. When it completes, open wordpad or paint and right click> PASTE to paste the created picture.
'How to copy a .bmp file to the clipboard using JB code by xxgeek 'Using CMD and PowerShell to help where JB is lacking.
nomainwin open "Copy .bmp to Clipboard" for graphics as #1 'draw something onto the Graphic Window (or it could be a graphicbox as well) #1 "home ; down ; size 20 ; color red ; circle 100" #1 "color blue ; size 50 ; circle 50" #1 " color red ; size 5 ; circle 5" #1 "flush"
' lets create a .bmp file from what's on our Graphics Window and save it to DefaultDir$ #1 "getbmp scr 0 0 260 260" bmpsave "scr", "MyPicture.bmp"
'now lets write a .bat file that will copy our .bmp file to the clipboard open "bmpclip.bat" for output as #clip #clip "powershell -command Add-Type -AssemblyName System.Windows.Forms; Add-Type -AssemblyName System.Drawing; [System.Windows.Forms.Clipboard]::SetImage([System.Drawing.Image]::FromFile('%1'))" close #clip
'now RUN the bat file 'so it can be pasted into Microsoft Paint'or Facebook, Messenger, or Wordpad, etc run "cmd.exe /c bmpclip.bat MyPicture.bmp",hide notice "Ready to paste into another app that supports pictures" close #1 end
|
|
|
Post by xxgeek on May 9, 2024 19:26:26 GMT
It turns out the above code works in Windows 10 Pro, but not in Win 10 Home version.
Here's code that works in both, and hopfully Win 7 and 8. But I can't test it..
'How to copy a .bmp file to the clipboard using JB code by xxgeek 'Using cmd.exe and powershell to help
nomainwin open "Copy .bmp to Clipboard" for graphics as #1 'draw something onto the Graphic Window (or it could be a graphicbox as well) #1 "home ; down ; size 20 ; color red ; circle 100" #1 "color blue ; size 50 ; circle 50" #1 " color red ; size 5 ; circle 5" #1 "flush"
' lets create a .bmp file from what's on our Graphics Window and save it to DefaultDir$ #1 "getbmp scr 0 0 290 300" bmpsave "scr", "MyPicture.bmp" q$=chr$(34) ' a quote character run "cmd.exe /c PowerShell -NoProfile -ExecutionPolicy Bypass -Command ";_ q$;"Add-Type -AssemblyName System.Windows.Forms; ";_ "Add-Type -AssemblyName System.Drawing; ";_ "[System.Windows.Forms.Clipboard]::SetImage([System.Drawing.Image]";_ "::FromFile('MyPicture.bmp'))";q$,hide notice "Ready to paste into another app that supports pictures" close #1 end
|
|