- Joined
- Sep 9, 2020
- Messages
- 384
- Reaction score
- 31
Softcoding is a tricky concept, it's hard to know what is and isn't softcoding. So, here's a little guide to help clarify some things, as well as a few examples!
What is "softcoding"?
Softcoding is the action of making a line of code that can interpret some data, and then modify your game or take actions accordingly. That might confuse you, so here's a better explanation. Note: this is the common way the term is used on DiamondFire, and while often useful, can be a bad habit at times. You should know when it's useful, and when you're just overcomplicating your code.
Softcoding is when you can have a single line of code (or multiple lines, for organization), and can make multiple parts of your game without creating a lot of standalone code. For example, take homchom's menu system, with it's menu page feature. You could make all of those pages by hand, each gui connected to some unique "Next Page" and "Last Page" items on the ClickItem function. Or, you could use his simple system that automates that all for you, and you only have to set some variables and call a function. That, in itself, is the essence of "softcoding", making your code smaller by adding a system that will automate tasks that would take up multiple lines of code if hardcoded. What if you want to softcode something yourself, instead of putting in some premade functions? That's where this next section comes in.
How you can "softcode".
The exact way to "softcode" isn't set in stone, but is rather up to you. How to "softcode" is probably best taught with examples, so here's an example based on using abilities:
Let's say you need an ability system for your game, hooray! Let's assign every player a %defaultAbility variable. This will be set to the player's equipped ability, such as "Whirlpool." Now, we'll need variables for every ability. On join, let's make a function that creates those ability variables. For our example, let's create the list Ability-Whirlpool. This will contain the cooldown, energy cost, and function name for our ability. Let's say [ 600, 100, "WPoolFunc" ]. Now, we go to actually using our abilities. On Swap Hands, let's do multiple things.
Of course, this is a very specific example, and softcoding can be used for many different things, like crates, shops, "sound loops," and more. If you want to know how to "softcode" something else, feel free to ask someone on DF or in the thread comments!
Color key:
Text Number Dynamic Variable
What is "softcoding"?
Softcoding is the action of making a line of code that can interpret some data, and then modify your game or take actions accordingly. That might confuse you, so here's a better explanation. Note: this is the common way the term is used on DiamondFire, and while often useful, can be a bad habit at times. You should know when it's useful, and when you're just overcomplicating your code.
Softcoding is when you can have a single line of code (or multiple lines, for organization), and can make multiple parts of your game without creating a lot of standalone code. For example, take homchom's menu system, with it's menu page feature. You could make all of those pages by hand, each gui connected to some unique "Next Page" and "Last Page" items on the ClickItem function. Or, you could use his simple system that automates that all for you, and you only have to set some variables and call a function. That, in itself, is the essence of "softcoding", making your code smaller by adding a system that will automate tasks that would take up multiple lines of code if hardcoded. What if you want to softcode something yourself, instead of putting in some premade functions? That's where this next section comes in.
How you can "softcode".
The exact way to "softcode" isn't set in stone, but is rather up to you. How to "softcode" is probably best taught with examples, so here's an example based on using abilities:
Let's say you need an ability system for your game, hooray! Let's assign every player a %defaultAbility variable. This will be set to the player's equipped ability, such as "Whirlpool." Now, we'll need variables for every ability. On join, let's make a function that creates those ability variables. For our example, let's create the list Ability-Whirlpool. This will contain the cooldown, energy cost, and function name for our ability. Let's say [ 600, 100, "WPoolFunc" ]. Now, we go to actually using our abilities. On Swap Hands, let's do multiple things.
- Check that the %defaultAbility and Ability-%var(%defaultAbility) variables exist. If so, continue
- Make sure that a %defaultCooldown is at most 0, and a %defaultEnergy is at least %index(Ability-%var(%defaultAbility), 2) (Ability Cooldown). If so, continue.
- If both of the previous conditions are met, then set %defaultCooldown to %index(Ability-%var(%defaultAbility), 1) and subtract %index(Ability-%var(%defaultAbility), 2) from %defaultEnergy. Finally, set the local variable abFunName to %index(Ability-%var(%defaultAbility), 3) and use a call function named %var(abFunName).
- In the background, every tick, subtract 1 from %defaultCooldown.
- In the background, make sure to regenerate energy as you wish (pickups, kills, or over time)
Of course, this is a very specific example, and softcoding can be used for many different things, like crates, shops, "sound loops," and more. If you want to know how to "softcode" something else, feel free to ask someone on DF or in the thread comments!
Color key:
Text Number Dynamic Variable
See K_Sasha and SamMan_'s posts below, the use of ''softcoding'' in this thread is technically incorrect, as this refers rather to the idea of the removal of repeated code. When doing the repetition, refer to SamMan's three guidelines, saving time, usefulness, and... usefulness again.
Last edited: