How do i create a class of functions that i can reuse across my project?

Hi, I’m new to verse. I would like to create a class of functions that i can reuse anywhere in my project

for example, i’ve written a function that given an agent will tell me what team they are on

i want to be able to call that function from any class/device in my project, how do i go about this please?

You can just create a class in another .verse file like this:

utils := class():

    CheckPlayerTeam():void=
        # Your code

And to call your function anywhere, you need to call the class and the function in it:

utils{}.CheckPlayerTeam()
1 Like

Another way you can call functions/classes from any file is to use modules

Here have i made a modules with a function inside. I have made them public so i can use them use them in other modules/folders

utilss<public> := module:
    (Player:player).CheckPlayerTeam<public>():void=
        # Your code

in another folder i can now import that module and use its functions like this.

using {utilss} # import module

test(Player:player):void=
    Player.CheckPlayerTeam() # runs function from the other module

Its like you are making you own digest.verse files. By this tactic its important to have the file in the main folder like here where its inside my project name folder called STHB_Tower_Defense. (forum.verse has the module and called CheckPlayerTeam inside the folder script in another subfolder)

Code_9zmN62Vc2M

Its because when you make a folder its by default internal where it can only be used by files and subfolders in the folder. i dont know how to make a folder module public.

Also in my example i did not use a class, but works the same way. Just remember to use public

Here is some links if you want to read more about modules and Public

1 Like

thank you both very much for your help

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.