• Hey! Register here to create your account, engage with the community, and talk about what is new!

A General Idea of "Softcoding"

Prox

Moderator
Moderator
Joined
Sep 9, 2020
Messages
384
Reaction score
30
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.
  • 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)
Whoa, that's quite a bit to unpack. Basically, we make sure that the player's ability is a real ability, and make sure that the player's cooldown is 0, while the player also has enough energy to use this ability. After all of that, we actually run the ability, by setting the player's cooldown, removing the energy cost, and running a function related to the ability. This is what happens when the player actually uses the ability, and you need one of these for every single ability.

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:

LooserRIP

Notorious member
Overlord
Joined
Sep 6, 2020
Messages
98
Reaction score
54
Very simply put: Softcoding is the act of editing values that aren't specified in code.\
but yes great tutorial!
 

General_Mudkip

Retired Moderator
Overlord
Joined
Sep 6, 2020
Messages
362
Reaction score
95
Even simpleryly put: Softcoding in DiamondFire is making your code usable in as many places as possible
 
Last edited:

K_Sasha

Active member
Joined
Aug 16, 2020
Messages
40
Reaction score
45
Just a disclaimer: this is not the correct usage of this term. In computer science, hard coding and soft coding generally refer to bringing configurable values or constants out of your code and into more easily editable mediums such as configuration files or database tables. This is not really what is being suggested here.

All this thread is saying is that you should avoid creating duplicated code, which is definitely a good thing to avoid. Duplicated code is something that happens in all kinds of programming environments, and it is the cause of countless bugs, hours of wasted time spent on updating every duplicated piece of code, and much frustration. However, due to the limitations of DiamondFire's coding language, this seems to be something that happens much more frequently than usual.
 
Last edited:

SamMan_

Forum adept
Joined
Sep 6, 2020
Messages
120
Reaction score
72
Though one point of softcoding (or whatever you want to call it) that often times is forgotten is that it can lead to people overcoding their plot to the point of insanity. Sometimes, yes you can make a hazy mazy %var() system, but do you need to? Here's some good questions to ask:
  • Will this save me time overall?
  • Am I giving my system the capability to do something that actually it will never need?
  • By removing hardcoded value(s), sure I make it easier to add new values, but will the inputs ever actually need to change?
That is, unless you know the system is overdesigned but are just doing it anyway for the fun & practice, in which case go ahead :)
 

General_Mudkip

Retired Moderator
Overlord
Joined
Sep 6, 2020
Messages
362
Reaction score
95
Will this save me time overall?
Yeah this is important, I often find myself soft coding things just for the sake of softcoding, when I could save more time by just hardcoding it. It's important to think about how often you'll need to use the feature you're coding, what things you need it to do, how general it can be, etc. to help you discern whether or not you should soft code it.
 

Vulcano

Forum adept
Overlord
Joined
Sep 11, 2020
Messages
243
Reaction score
64
It is also useful with templates, you can now use stuff in other games you're working on, which will save a lot of time, or for code vault
 

LooserRIP

Notorious member
Overlord
Joined
Sep 6, 2020
Messages
98
Reaction score
54
I agree with K_Sasha and SamMan, i see the term "Softcoding" being thrown around a lot and used incorrectly, and yes sam is also right you shouldn't softcode all the time, only when it saves you time for the present or the planned future.
 
Top Bottom