#How would you go about making variations of scripts

1 messages · Page 1 of 1 (latest)

cobalt aurora
#

Or multiple items with similar scripts...
I don't have a lot of experience in prigramming snd this is feeling like something I can't even put the words to but let me try to see if I can explain what I'm trying to do...

I'm trying to make something like an RPG. And I've added functions for things like using items and drinking potions in the barest sense. But how would you go about having lots of different items with different functions? Like, should each potion be its own script? Then you can't have them all be in the same class_name as items or potions. Or maybe all potion abilities should be one big script, and the variations of the "potion" item choose which functions in the script to run? Then we have a huge script in each individual item, which will tale up resources, right?

This is my first time posting here, so let me know if i' doing anything wrong and thanks in advance. I'm just doing this as a summer hobby, so this is the only way I think I'd be able to get some advice on this.

restive trellis
#

You can write a base script and then extend your original base class. An example might be something like this:

class_name Spell

@export var name: StringName
@export var mp_cost: int = 0

func _init( strName: StringName, intCost: int ):
    name = strName
    mp_cost = intCost```
Then you could bolster that with:
```extends Spell
class_name AttackSpell

@export var damage_value: float = 10.0
@export var damage_type: int = Globals.DAMAGE_ICE

func calculate_damage( casterINT: int, defenderINT: int ) -> float:
    var value: float = damage_value
    # add calculations
    return value```
#

In this instance, the 'AttackSpell' has all the properties of the original 'Spell' class, but with more added on.

#

Items can similarly be extended.