Files
sfall/docs/best-practices.md
T
burner1024andGitHub 5f0c5ae1fa Better docs (#241)
* website skeleton

* updated bunder to 2.0, added caching

* fix missing plugins?

* enable deploy for the branch, try to save cache

* need to use relative path?

* fix missing css

* use doc theme

* really enable doc theme?

* mayeb this time

* come on baby

* how about now

* please ?

* pretty please

* ehhh

* working theme

* added hooks

* formatting

* formatting 2

* added doc yaml from bgforge mls 1.0.7

* no need for nav order

* link reference

* hooks on top

* added global scripts

* pages are generated, exclude them

* generate site

* pip3 ?

* maybe now

* hooks page is generated automatically

* added table of contents to pages

* don't waste so much space

* switch highlight classes

* mark functions as code in description

* more formatting

* reformat doc with python

* loaded offsets

* opcode is loaded into yaml, txt no longer necessary

* mark unsafe functions

* restore hooks page

* clarification

* deduplicated hooks doc

* saner TOC

* typo

* move more docs

* hook scripts doc is now in md

* arrays doc is now in md

* added data types page

* added more info about old behaviour

* minor formatting issues

* moved more function docs to yaml

* all sfall functions docs are transpiled to yaml format

* formatting

* fix format

* add subcategory support

* simplified yaml format, added structure doc

* simplified structure and added clarification

* generated a separate page for hook types

* formatting

* disambiguation

* format clarification

* move get_map* to subcategory: doc is not relevant for other functions

* simple permalink

* fix links

* included more info on the main page

* more clarification

* rename offset > opcode

* try to get more sensible baseurl

* added best practices page

* what's up with the slashes

* allow parent pages with no content

* separate docs for direct memory access functions

* added latest functions

* fixed hook types link

* move get_explosion_damage to macros

* removed duplicated comment

* removed old comments

* added hook ids

* lowercase sfall

* more sfall lowercasing

* added proper permalinks

* changes from mr.stalin

* fix typos

* clarification

* fix direct memory access page

* fixed top navlink

* fixed urls

* checked sfallgv.sav, it's really not bloating much

* format clarification

* shorter name

* add mixed data type, sort

* add proc type, link hooks functions

* use same terminology

* added bool

* rearranged index

* added unsafe label

* move to root

* add stats

* more upper/lowercase

* should work now

* added build status

* added combat category, added description for modified_ini, moved global script functions into a subcat

* special note for set_self

* typo

* enable children

* cleanup

* move lists to arrays

* show header filename for macro instead

* rearrange more items to be more intuitive

* build on bionic

* separate object manipulation

* added object manipulation link to home

* typo

* formatting

* Added a note about charges

* punctuation

* formatting

* moved floor2 to math

* changed label color

* moved art and appearance to animations

* name too long

* search note

* moved exex_map_update to maps category

* moved more functions from other to skills

* too much blue

* formatting

* moved art_cache_clear to art section

* empathize that var name must be exactly 8 characters long

* update usages for inc_npc_level

* separate objects, scripts and variables

* updated url

* moved get_string_pointer to strings

* updated add_extra_msg_file doc

* typo

* latest doc updates from develop

* updated default layout from upstream

* applied local changes: subcategory list

* remove unnecessary backticks

* added new functions

* fix STD_PROCEDURE_END display

* formatting

* don't fail on missing hook id

* formatting

* updated doc from upstream

* added optimization and sslc pages

* order ssl and optimization pages below home

* really order optimization on top

* merge objects_in_radius variants

* updated from upstream

* tone down link color

* fixed formatting for updated theme

* updated travis for ruamel

* added favicon

* restored separator between functions

* updated functions.yml

* updated sfall functions

* rearranged some window and object function

* hook updates, pre-arg renaming

* hook args renumbering

* merged upstream

* added new hooks and functions from upstream

* remove the long-winded note about macro

* switch to gha for jekyll deployment

* sudo for deps

* try to fix ruamel missing

* switch build to master only, ref https://github.com/phobos2077/sfall/pull/241#discussion_r580365212

* update status badge for https://github.com/phobos2077/sfall/pull/241
2021-02-24 11:40:24 +03:00

2.5 KiB

title, permalink, nav_order
title permalink nav_order
Best practices /best-practices/ 2

Best practices

{: .no_toc}

  • TOC {: toc}

Mod compatibility

  1. If it can be done in a [global script]({{ site.baseurl }}/global-scripts/), do it in a global script. Combined with hooks, they are extremely powerful, possibilities ranging from creating new perks to UI scripting to prototype altering on-the-fly. While scripting does take a bit longer to get started, and hacking prototypes directly with GUI programs might look easier at first, consider that:
  • Scripts from different mods modifying the same thing can actually be compatible with each other. Binary files can't.
  • Scripts can be version controlled and thus are much more easier to maintain.
  1. If you're using [set_sfall_return]({{ site.baseurl }}/hook-functions/#set_sfall_return), always couple it with [set_sfall_arg]({{ site.baseurl }}/hook-functions/#set_sfall_arg) for the corresponding arg(s), unless you have a specific reason not to. Detailed explanation is available [here]({{ site.baseurl }}/hook-functions/#register_hook_proc).

  2. Pick yourself a 2-3 character modding prefix. Use it for:

  • global script names
  • global variable names and saved array names
  • debug messages

This will ensure (to some degree), that another mod doesn't overwrite your scripts, doesn't mess with your global variables, and that debug messages coming from your scripts can be distinguished easily.

For example, if you pick prefix "a_", your script could be named gl_a_myscript.int, and might look like this:

  #define NAME "gl_a_myscript"
  #define ndebug(message) debug_msg(NAME + ": " + message + "\n")

  procedure start begin
    if game_loaded then begin
      set_sfall_global("a_myvar", 1000);
      ndebug("initialized");
    end
  end
  ...

Performance

  1. Do not abuse [set_global_script_repeat]({{ site.baseurl }}/global-scripts/). Whenever possible, register your script as a [hook]({{ site.baseurl }}/hooks/) instead. You can register the same procedure at multiple hook points, if necessary.
  • If you have set_global_script_repeat(300) in your script, you're probably doing something wrong. That's an invocation every 3-5 seconds, approximately.
  • If you have set_global_script_repeat(30), you are definitely doing something wrong. Look for suitable hooks harder, think of another way for implementing it, ask fellow modders for help.