2
$\begingroup$

I wrote the code for a puzzle game. It's written in a notebook that I would like to share on the internet:

game[] := 
  Dynamic[DynamicModule[{pt = {0, 0}}, 
    Magnify[EventHandler[
      ClickPane[
       Dynamic@Graphics[display[]], (pt = #) &], {"MouseClicked" :> 
        clicks$manager[pt[[1]], pt[[2]]]}], 
     7]]];    

display[] calls a Graphics[...] user interface. There is a Rectangle[{0,0},{1024,1024}] background and images appear in top of it. clicks$manager[x,y] triggers actions depending on what is currently displayed by the UI. game[] is the single-line input I shift-enter to begin playing the game.

When I shift-enter the code, the game imports the images that will be used by the UI from "path/images/image01.jpg", "path/images/image02.jpg", ... . All images a stored on my computer.

The game is single player: one vs the AI. The AI has a few difficulty levels. One level calls a log of all the previous games to be able to pick the best decisions. This database is actually only a table written in a log.txt file stored on my computer. At the end of each game, the log is exported to "path/log/log.txt". At the beginning of each game, log.txt is imported from "path/log/log.txt"

My question is from that point, what do I need to do to share this game on the internet? I'd like to have a webpage that starts to display the UI at once. I consider webmathematica to let anyone, not only Mathematica users, have access to my UI. Is that the only option? If yes, where will I put the notebook, the images and the log.txt that the game requires? What modification will I have to make to the code? Am I sure that I will be the only one to have access to the log.txt file? Are there examples of websites for puzzle games made by amateurs that are powered by webmathematica? (I googled it but I can only find www.wolfram.com pages)

Thank you.

$\endgroup$
  • $\begingroup$ There's CDF, but that needs the user to download the Player. If you're taking the webMathematica route: does your license allow for this? $\endgroup$ – J. M. is away Jan 3 '17 at 13:47
  • $\begingroup$ Users with premier service have access to webmathematica amateur which may work. I have never seen a Wolfram Language based game online though, personally. The examples at wolfram.com/products/webmathematica don't seem to be particularly snappy, so I don't know how realistic playing a game would be. $\endgroup$ – user6014 Jan 3 '17 at 14:48
  • 1
    $\begingroup$ You should acknowledge that you have simultaneously asked this exact question on another forum ( community.wolfram.com/groups/-/m/t/989082) and keep both forums updated with links to answers. Otherwise, if you have an answer, folks are then wasting their time helping you on the other forum. $\endgroup$ – JimB Jan 3 '17 at 17:12
  • $\begingroup$ @Jim Baldwin Indeed the question was asked on both forums. $\endgroup$ – Domiinic Jan 3 '17 at 17:34
  • $\begingroup$ @user6014 It seems it is possible to do by linking my server to Wolfram Cloud. But if it's easy enough I wonder why we don't find more examples of mathematica apps used for game puzzles or educational purposes. $\endgroup$ – Domiinic Jan 3 '17 at 18:01
4
$\begingroup$

This applies to any Wolfram Cloud based web application, not simply to your question, but there are say 4 steps involved in creating a web app. Hopefully some of this carries over from WC to webMathematica.

1) Create root directory on server

This will be the main way people access your app. Give it a short, easy-to-remember name.

2) Save all resources

Toss all your jpgs in a imgs directory under your root directory, put your log.txt in a difference directory (maybe log) so you can make that directory publicly accessible at some point. Put your code in a pkg directory. This is just good housekeeping but it will make your life easier.

3) Configure interface

Interfaces in the Cloud are very different from those on the desktop. Various UI structures we use in Mathematica look and behave differently in the Cloud. You'll need to test and tweak this to get everything right. Use FormObject and friends when possible, as these render faster, work cleaner, and generally are just more efficient than Cloud notebooks. Toss all your interface pieces into your main directory. Give your primary interface a simple name, such as your root directory name or main. Note that Cloud doesn't accept index.html as a name. Clearly that's reserved.

4) Set permissions

Usually you want your resources to be read only: (Permissions->{All->{"Read"}})

Your interfaces to be read and interact only: (Permissions->{All->{"Read","Interact"}})

and your logs to be write only:

(Permissions->{All->{"Write"}})

When you have all these pieces in place simply provide the URL to your main interface notebook. Generally this will look like: "https://www.wolframcloud.com/objects//root/main" or if they're coming from Mathematica: CloudObject@"user:<user-short-name>/root/main.

Make sure that all the pieces reference each other, not whatever directory structure you had in development, and you're good to go.

One word of warning: Cloud is not good for highly interactive structures unless you have functionally infinite Cloud Credits. Every interaction someone performs (calling Alpha, moving a slider) will eat some of your allotment. Moreover Cloud is too slow and buggy for games (this will probably improve in the future). The kernel connections are iffy (this is why one often gets weird failure messages on even simple computations) and the notebook rendering takes forever.

$\endgroup$
  • $\begingroup$ Thanks MB1965 for the answer ! It looks that what I want to do is already possible by using a server and the Wolfram Cloud, although with limited Cloud Credits. $\endgroup$ – Domiinic Jan 3 '17 at 17:41
  • $\begingroup$ It will take a lot of testing to make it appear alright for the end-users and I certainly have other questions. For example: The code that I will put in my server's pkg directory, is it the notebook.nb with the game[] function include for display? Are the permissions given in that notebook on the server ? $\endgroup$ – Domiinic Jan 3 '17 at 17:49
  • $\begingroup$ The code should be in .m files. If you aren't used to packages there are many good questions and tutorials to look at. You set the permissions when you use CloudDeploy or via SetOptions on the CloudObject. Likely you will also need to read up on cloud basics. $\endgroup$ – b3m2a1 Jan 3 '17 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.