Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Code Snippets and Such Sticky

A topic by spacerace127 created 57 days ago Views: 259 Replies: 7
Viewing posts 1 to 6
Submitted (1 edit) (+4)

Some folks asked me to share some code I showed off in another thread, and I decided I should start a thread where we can all share any code/decks/contraptions/modules we think may be useful for the jam. I'll start off with this.


This here is my dialog formatter! Basically, it takes some basic text and gives fonts to character names and adds commands automatically.

One of the first things I wrote in Decker, so hopefully it's not too buggy. Since it's pretty involved, I decided to upload it into it's own deck, with tables and such set up already for you to use! The deck includes some documentation and steps on how to get it into your project, but basically:

  • Copy the settingsDialog card into your project (can do this by going to the card, and clicking on the menu options Card -> Copy Card. then go to your project and do Edit -> Paste Card)
  • Copy the top level deck script into your project's top level deck script (go to File -> Properties -> Script)
  • Make sure you have the dd and pt modules.
  • And now go wild! Edit the chars table to match your characters. The script puts character names on their own line, but feel free to go into the code and change that (look for new_format in the dd_format_helper method).
  • To use, call dd_format in addition to dd.say. The deck shows some examples of this.

Not entirely sure how to upload the deck here, so for now I'm just putting it in a pastebin lol (don't like using google drive or whatever)

https://pastebin.com/XdhR9UMW

Download the text file, and then do either of these:

  • Rename the file and replace .txt with .deck. This will convert it into a decker file.
  • Drag the file onto the decker.exe, and it will open the file. Save the file as a decker file.

Feel free to use this with or without credit. Let me know if you run into any bugs! Maybe I'll turn this into a contraption at some point and upload it to the Decker forums, but for now this works hehe.

Submitted(+3)

THANKS SO MUCH

Submitted(+2)

Oh awesome!!! This is so useful, thank you for sharing with us <3

Submitted(+4)

Thank you guys! If instead you want to use this as a contraption, I spent some time to figure out how to make one with this hehe. Instead of copying the whole card, just copy and paste this code directly in Decker.
https://pastebin.com/zvHRUiUb


Add your rows and characters and select your fonts! It also has text attributes for you to handle the name formatting. "Script names" will be how names are typed in your script. "Dialog names" is how names will show up in the dialog. Keep "%s" but change anything else if you want. By default, script names looks like "%s: " and dialog names looks like "%s\n" (the new line is a literal new line in the text field). If you're feeling adventurous, feel free to go into the contraption prototype code and add more columns if you want to customize more things for you characters.

To get this working for all cards and to get the talk sounds working, here's the working code below that you can copy and paste into your top level deck script. (replace <card1> with the card that the contraption is located in, and <dialogFormatter> with the name of the contraption). After this, just like with the deck code, you just need to call dd_format with dd.say.

on dd_format text hide_command do
 <card1>.widgets.<dialogFormatter>.dd_format[text hide_command]
end
on command x do
 char_table:<card1>.widgets.<dialogFormatter>.characters
 if (sum (extract command from char_table) like x) > 0
  talk:first extract talk where command=x from char_table
  dd.style[dd.getstyle[].tsound:talk]
 else
  pt.command[deck x]
 end
end

You can call the method dd_format[] and get the attribute .characters from the contraption. "characters" returns the table, and dd_format[] runs the formatting script.

Submitted(+1)

Hey I have a small issue, I added a column called "color" to assign a color to each of my characters. From there, I added a line in the deck script that would extract the color value from the table and make it the color of the text that appears in dialogizer (with the .fcolor attribute). I tried mirroring how you handled it with the talk value in your lines of script, but I must be doing something wrong because it doesn't work. I cannot for the life of me figure it out on my own.. can I get some help please ToT

Submitted(+1)

Sure I can help out! How are you storing the colors? Are you putting them in as hex codes, pattern number, or color names? If you're using color names (like red, orange, blue, etc), this is how you would do it 

... the command script, handling colors should go in the same spot as where we handle talk sounds
 if (sum x=(extract command from char_table))>0
  # gets the current style
  o:dd.getstyle[]
  # gets the talk value
  o.tsound:first extract talk where command=x from char_table
  # heres the new code!! "color" should be replaced with the name you used in the table
  c:first extract color where command=x from char_table
  o.fcolor:colors[c]
  # end of new code
  # apply the style
  dd.style[o]
 else
... rest of the script

This should work. If you're using pattern numbers instead, instead of colors[c], you just feed in "c" directly into the fcolor (since fcolor is looking for a pattern number). Since fcolor is looking for a pattern number, you probably can't use a hex code, and instead would need to modify the color palette of your game if you want to use different colors outside of the default colors.

(+1)

Just FYI, All About Color includes a module ("col") which can handle conversion between RGB, HSV, and CSS names and find the closest match in the currently configured Decker palette.

Submitted(+1)

Thank you so much!! I was missing the part where you define c, I have no clue how that actually works but it works perfectly :')