Squirrel: Declaring a function inside a class confusion

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
Stefmachine
Engineer
Engineer
Posts: 6
Joined: 13 Sep 2021 14:05

Squirrel: Declaring a function inside a class confusion

Post by Stefmachine »

Hi,

I've been checking the documentation about pitfalls.
It says that declaring a function inside a class might cause issues.

Code: Select all

class Util{
    function Util::GetMsg(){
        return "Test";
    }	
}
That is kind of obvious since the Util:: is redundant.
The documentation suggests declaring it next to the class like so:

Code: Select all

class Util{
    	
}
function Util::GetMsg(){
   return "Test";
}
However declaring a function the expected-normal-no-c++-header-file way seems to work fine for me.

Code: Select all

class Util{
    function GetMsg(){
        return "Test";
    }	
}
Am I going to run into issues later on if I keep doing this?

Thank you in advance.
AAAHogEx
Engineer
Engineer
Posts: 117
Joined: 30 Jan 2022 15:37
Location: Japan

Re: Squirrel: Declaring a function inside a class confusion

Post by AAAHogEx »

Code: Select all

class Util{
    function GetMsg(){
        return "Test";
    }	
}
Am I going to run into issues later on if I keep doing this?
I wrote one AI in this code style and had no problems at all.
Stefmachine
Engineer
Engineer
Posts: 6
Joined: 13 Sep 2021 14:05

Re: Squirrel: Declaring a function inside a class confusion

Post by Stefmachine »

All right!

Thank you.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 10 guests