Skip to content

Keep references to scripts - implement the super() function through the ModLoader #231

@KANAjetzt

Description

@KANAjetzt

Ste — Yesterday at 16:48
just remembered this convo from the dk playtest modding channel

I'm looking at docs for modding and I have a question about install_script_extension
lets say I want to modify one function/method in a vanilla script let say Monsters.gd
Then it would be something like that

extends "res://content/monster/Monsters.gd"

func spawnWave():
   .spawnWave() # Call original spawnWave func
   print("Print in console something") # Execute extra code at after the original method one 

but if I would want to rewrite part of the function, then it's impossible and would need to rewrite it as
whole?
so without calling the function instead but just write script? Also can I call original function that way? And do I assume correct that local varibles of that function would not be available in new function to refer directly?
Ste — 17.04.2023 15:23
yes you have to copy the method and add your own stuff. i'm also not sure how we could implement inserting code like that.
it's a little dependant on good architecture of the game sadly
yes that is the proper way to call the "parent" function
i haven't tested the local variable thing, but i also assume no
Ategon — 17.04.2023 15:37
there is technically a way if you keep the references to both scripts instead of extending then implement the super() function or something through the mod loader
Ste — 17.04.2023 15:42
do you have an example?
Ategon — 17.04.2023 15:48

Monsters.gd (1)
func example():
  print("Test 1")

Monsters.gd (2)
func example():
  Loader.super("example")
 
 
func monsters_scripts = [load(path).new(), load(path2).new()]

func super(type, args = []):
    monsters_scripts[0].callv(type, args)

very basic but its an example of the type of system
Then for any normal functions it would start from the back of the array and trigger the first one that matches in a file (checking using has_method())

Ste — Yesterday at 16:48
we should look into that

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions