Advertisement
a7na

dialogue module WOOHOO!

May 2nd, 2024 (edited)
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.68 KB | Source Code | 0 0
  1. --[[// YOU CAN COPY THIS INTO YOUR SCRIPT FOR EASIER REFERENCE:
  2. This Dialogue module is inspired by the way the Ren'Py visual novel engine formats its scripts.
  3. You may want to read up on that, as well as have some scripting knowledge up your sleeve to properly use this module.
  4. - for reference, stuff is named: serial? = { dialogue = {scene = {{line}; {line};}} }
  5. - to add random dialogue choices, do [1] = {(dialogue here)}, [2] = {(dialogue here)}, etc. If not you should remove the indices entirely.
  6. - each dialogue must have a scene named "START"; it will be the first one iterated.
  7.  
  8. - Settings -> optional settings table, values inside are also optional:
  9.     - UseProximityPrompt [false] -> self-explanatory. *DEFAULTS TO CLICKDETECTOR IF FALSE*.
  10.     - CancelDistance [0] (NEEDS OBJECT) -> studs from the physical dialogue source, when exceeded will auto-cancel the dialogue. Set to 0 to disable.
  11.     - NoCancelling [false] -> self-explanatory
  12.     - NoSkippingText [false] -> disable clicking the text to skip typewriting. for lazy people.
  13.     - Autopilot [0] -> disable advancing lines, instead waits the defined time before automatically advancing. overridden by _timer.
  14.     - FreezePlayer [false] -> players can't move when dialogue is active.
  15.     - DisableCoreGUI [false] -> disables *all* coreGUIs e.g. leaderboard (preferably for more cinematic scenes).
  16.  
  17. - Elements in a scene are either:
  18.     - a line, e.g. -> {str = "hello!"}
  19.     - an anonymous function which can do anything really
  20.         - including yielding, e.g. -> function() task.wait(3) print("function just yielded!") end
  21.             - there will be a loading sequence for text ('' > '.' > '..' > '...') if the function does yield; you can also use that to add conversational pauses
  22.             - to run the function parallel to the next line, do coroutine.create(function() .. end); DialogueScript will resume them.
  23.         - or conditions RETURNING LINES, e.g. -> function() return if b then {str = "b true!"} else {str = "b false!"} end;
  24.             - you can execute whatever before returning the line, it doesn't matter
  25.  
  26. - Each line can optionally have:
  27.     - str -> Text said by the speaker, does not necessarily need to be defined. Should be defined first in the line for readability.
  28.     - speaker -> The person speaking: Not necessary if the previous line's speaker is the same.
  29.         - just set it to "" for narration/soliloquies.
  30.     - choices -> spawns choices on click jumps to specified sceneToJumpTo.
  31.         - in format {["choice1"] = "sceneToJumpTo", ...}
  32.         - if sceneToJumpTo = "CONTINUE", then it continues to the next line without changing scenes.
  33.             - (from a developer standpoint "CONTINUE" could just be nil, but that's messier)
  34.         - pretty niche but choices also supports functions, e.g. -> {["func_choice"] = function() ... return "scene2" end), ...} (use this as you will)
  35.     - jump -> simply jump to specified scene
  36.     - (lines which don't lead to anything else will end the dialogue!)
  37.    
  38.     - line settings (put it as extra arguments)
  39.         - _basespeed [0.02] -> delay of the next *character* appearing during typewriting.
  40.             - changing this number also proportionally changes punctuations' delay of 0.18, (calc'ed as base * 9)
  41.         - _timer [0] -> force-skip to the next line after waiting the specified time, instead of waiting for a player click.
  42.             - has priority over choices: they must be made before the timer runs out, otherwise it'll just continue to the next line.
  43.         - _delay [0] -> yields the specified time before typewriting, playing the "..." loading sequence.
  44.  
  45. * rich text is supported for ALL seen text, including the speaker's TextLabel.
  46. ** you can use _G.DialogueRepository for globally shared variables — you figure that out.
  47. >>> This module allows for a lot of creativity. You do you, have fun!
  48. //]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement