Picking icon states at runtime
Some of you may have wondered: "How do I pick a random state from an icon at runtime?" Here's how!
What you need for this project:
* The BYOND package (Dream Maker/Dream Seeker)
* An icon with multiple states
Now let's get started. This is a very simple thing to do; all you do is use a few of the built-in procs Dantom has so kindly provided. We'll use:
pick() ...picks a random item from a list.
icon_states() ...generates a list of all icons in a file.
There -- now you have a random (totally random!) map generator.
Now, say you want to pick an icon state from a icon you define. You'd have to pass the icon's name into icon_states():
Now, if you wanted to view all the icon_states of a file, you would have to loop over all of its states:
Save files are a big part of BYOND nowadays. People use them for many things, such as saving character progress and saving pieces of their games.
Step one: understanding the basics
This is a really basic code that I will comment to explain:
Step two: single var saving
"That was easy," you think. "But what if I only want to save certain vars?" Well, you'd have to save them directly into the savefile. Here's how.
Step three: using what you've learned
Using both of the previous steps, you can now create a sort of save system.
Now, were savefiles as hard as you thought?
For further reference on this subject
Many people don't know that you can make dynamic web pages using BYOND's built CGI (Common Gateway Interface) functions. CGI is commonly used to process HTML form input and generate new HTML forms based on the result.
What you'll need for this project:
* Dantom.CGI (Dantom's CGI library located here;
* Dantom.htmllib (Dantom's html library) located here;
* A server that allows BYOND CGI (every server has its own rules about this; if you don't know whether a server supports or allows BYOND CGI, you'll need to ask the server administrator).
Now that you've gotten that out of the way, lets get started.
Step one: including the libraries
When you open Dream Maker, open or create a new enviroment. Now click the "Lib" folder icon; you should see dantom.CGI and dantom.htmllib in there. Check the boxes next to them, and now it should look like this:
Step two: coding your first form
Now that you've gotten those libraries included, you can make a form to use with your CGI. Here's an example form:
Form //defined in the htmllib
There -- that's your first form. It should look like this:
Step three: turning your form into cgi
Using the code above add this line to your code:
CGI/default_form = /Form/startup
Now upload your .dmb file to your server, and see the results.