Subroutines: Modules and Functions

Here is the code used in this lesson:


//MODULES AND FUNCTIONS

Module module1 {
    String varMod
    Array arStrMod
    
    void function1 (String param1, Integer param2, Bool param3) {
    
    }
    
    void function2 () {
    
    }
    
    void function3 (String param1) {
    
    }
}

Model Person {
    String name
    String lastName
}

Module module2 {
    Location location
    Integer int
    
    //RETURN
    void function1 () {
        module2.location = Location()
        location.latitude = 55.55
        
        module1.varMod = "hello"
        
        varMod = "asdf" //Error, you have to use the module to access the variable
    }
    
    Person getPersonByName (String name) {
        return broker.localPersistence.get(name)
    }
    
    String getName (String lastName) {
        return "name"
    }
    
    void processPaymentsSalaries (Array employees) {
        service.processPayments.call(employees)
    }
}

//FUNCTION CALLS

RuleContext ctx {
    Rule rule {
        module2.function1()
        
        Person per = module2.getPersonByName("Pepe")
        
        String str = module2.getName("Argento")
    }
}

> Start Basic Level