For example, this works, but I understand that this is bad practise:
Code: Select all
function1() {
foo := "Hello, John!"
}
function2() {
function1()
if foo = Hello, John!
msgBox, Hello Mike!
}
global foo
function2()
Code: Select all
function1() {
foo := "Hello, John!"
}
function2() {
function1()
if foo = Hello, John!
msgBox, Hello Mike!
}
global foo
function2()
Code: Select all
function1() {
return "Hello, John!"
}
function2() {
foo := function1()
if foo = Hello, John!
msgBox, Hello Mike!
}
Thanks again! Your answers are always amazing! :-)boiler wrote:...
Code: Select all
function1() {
person1 := "John"
person2 := "Jill"
}
function2() {
msgBox, %person1%
msgBox, %person2%
}
function2()
Code: Select all
function1() {
person := []
person.1 := "John"
person.2 := "Jill"
return person
}
function2() {
person := function1()
msgBox, % person.1
msgBox, % person.2
}
function2()
Code: Select all
function1() {
global person
person := []
person.1 := "John"
person.2 := "Jill"
}
function2() {
global person
msgBox, % person.1
msgBox, % person.2
}
function1()
function2()
Code: Select all
global person1,person2
function1() {
person1 := "John"
person2 := "Jill"
}
function2() {
function1()
msgBox, %person1%
msgBox, %person2%
}
function2()
Code: Select all
function1(ByRef p1, ByRef p2) {
p1 := "John"
p2 := "Jill"
}
function2() {
function1(person1, person2)
msgBox, %person1%
msgBox, %person2%
}
function2()
Code: Select all
#SingleInstance force
#Persistent
mc := new MyClass()
mc.function1()
mc.function2()
class MyClass {
function1() {
this.person1 := "John"
this.person2 := "Jill"
}
function2() {
msgBox, % this.person1
msgBox, % this.person2
}
}
Code: Select all
mc := new MyClass("John", "Jill")
mc.function2()
class MyClass {
__New(name1, name2) {
this.person1 := name1
this.person2 := name2
}
function2() {
msgBox, % this.person1
msgBox, % this.person2
}
}
Code: Select all
fred := new Person("Fred", 21)
bob := new Person("Bob", 16)
MsgBox % fred.BuildGreeting()
MsgBox % "Bob can order alcohol: " bob.CanOrderAlcohol()
class Person {
__New(name, age){
this.name := name
this.age := age
}
BuildGreeting(){
return % "Hi, my name is " this.name ", and I am " this.age " years old"
}
CanOrderAlcohol(){
if (this.age >= 18){
return true
}
return false
}
}
Almost 4 years later and I found how to use Byref for my needs! Fantastic!boiler wrote: ↑20 Feb 2018, 16:03Another alternative is using ByRef, which allows you to return values directly into the variables in your function call:Code: Select all
function1(ByRef p1, ByRef p2) { p1 := "John" p2 := "Jill" } function2() { function1(person1, person2) msgBox, %person1% msgBox, %person2% } function2()