how to make many monsters with a "base script"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ManoD

hi guys, I’m very begginer on godot and I’m trying to make a pokemon like game, the thing is, I need to make the base stats of each pkmn I’m wondering if has a way to make a script with the stats, types and everything else that I can use as a base to every pokemon that I make

:bust_in_silhouette: Reply From: Inces

Sure, they are called classes.
Create new script, extending from whatever You want, and in the very second line of script, right below “extends”, use :

class_name =

You can introduce every variable shared by all pokemon there, and set all calculations. Exported variables will be different for every pokemon inheriting from this script.
When You will create pokemon scene You will simply inherit from your class, by entering your classname after “extends” keyword of a node. You can also create whole scene with this class script, and every time you make new pokemon choose “create new inherited scene”

:bust_in_silhouette: Reply From: ener


You can try to create a new script extending ‘Resource’. Then writing your stats down as exported variables.

class_name Stats
extends Resource

export var strength := 10.0
export var cooldown :=  1.5
export var life := 100

Then in another script on another node, you can use it as variable.
But first you need to create a new Resource in the Editor from the “” script.
Simply right-click in the filesystem tab and choose new resource.

Then search for “CharacterStatus” and you should find your own script. Click on it and save it as ‘.tres’ file. Now you should have created a Resource file from your gd-script.

Then you can for example use your new created resource on another node with the following script:

class_name MyCharacter
extends KinematicBody2D

# Assign it in the editor's inspector tab of your node.
export var char_status: Resource = preload("res://path/to/CharacterStatus.tres")

func _ready():
    print("Life: " + str(
    print("strength: " + str(char_status.strength))
    print("cooldown: " + str(char_status.cooldown)) -= 20.0 # take damage for example

    print("Life now: " + str(

With that you could create a status.tres file for one type of Monster/Character/Thing and attach it to all of them. And of course accessing and modifyng it.

Now we should be able to see in the console the printed values:

#The print output could be something like this:
Life: 100
strength: 10
cooldown: 1.5
Life now: 80