Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Script error cant find method ..."Method Name"

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 103

Script error cant find method ..."Method Name"

Post by jamisco » Sun Jun 25, 2017 2:41 am

So I have a methed called

Code: Select all

public void ActivateTheGunner()
{
	//Activating DA Gunner
}
but when I run my game and

I'm using a script trigger object in map editor to trigger the method, it says this error

Script Error
Can't find method 'ActivateTheGunner()' in map script. Expecting:
public void ActivateTheGunner()(TriggerArgs)
{
}

but when I'm using the object itself to trigger the method, it says

Script Error
Can't find method 'ActivateTheGunner()' in map script. Expecting:
public void ActivateTheGunner()(CreateTriggerArgs)
{
}


In the script method for the object in map editor, ive tried both 'ActivateTheGunner()" and 'ActivateTheGunner", Neither one works and I can assure you its not a spelling mistake... So I'm guessing my problem has to do with the games concept of triggers, If it does please tell me what triggers are and what they are used for and what I'm doing wrong here , else if triggers aren't my problem, you can still tell me what triggers are if you want (Please) and please tell me a way to fix my problem.

Thanks
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Post by Gurt » Sun Jun 25, 2017 4:31 pm

You're just missing the arguments to the function - all triggers require the "TriggerArgs args" parameter:

Code: Select all

public void ActivateTheGunner(TriggerArgs args)
{
}
0 x
Gurt

jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 103

Post by jamisco » Sun Jun 25, 2017 8:37 pm

Its still not working. Now I get this....

Script Error
Error in method 'ActivateTheGunner(TriggerArgs)' in map script. See the exception for more details:
--- Exception ---
Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at SFDScript.GameScript.ActivateTheGunner(TriggerArgs args)
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Post by Gurt » Sun Jun 25, 2017 10:38 pm

It indicates a runtime error in your script which is
Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
in your method ActivateTheGunner(TriggerArgs args)
0 x
Gurt

jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 103

Post by jamisco » Mon Jun 26, 2017 8:03 am

So the trigger args part isn't the problem then?
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Mon Jun 26, 2017 4:14 pm

jamisco wrote:
Mon Jun 26, 2017 8:03 am
So the trigger args part isn't the problem then?
The problem refers to something you have declared but not initialized or is set to null.
For instance, if I declare a type from the API classes, like IObject I cannot read his values without initializating it before:

Code: Select all

public void OnStartup()
{
IObject a;
a=null;
Game.ShowPopupMessage(""+a.GetHealth());
}
This code will generate a null reference exception.
1 x

jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 103

Post by jamisco » Tue Jun 27, 2017 6:30 am

Thx Jak, I found the "broken code" in my code, problem is, it doesn't look broken.

the broken part is within the foreach statement.

IPlayer[] Enemies = new IPlayer[] { }
int i = 0 // used for enemy array
foreach(IPlayer plyr in Game.GetPlayers())
{
PlayerTeam Plyr_team = plyr.GetTeam()
if (Plyr_team != TheGunner.GetTeam())
{
Enemies = plyr
i++
}
}

I really do not see what is causing the object reference error, everything is initialized..
also ignore the lack of semi-colons for some reason when I add them to the post, I cant post my post
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

User avatar
JakSparro98
Superfighter
Superfighter
Posts: 530
Joined: Fri Jul 15, 2016 7:56 pm
Started SFD: PreAlpha 1.0.5
Location: Rome, Italy
Gender:
Age: 25

Post by JakSparro98 » Tue Jun 27, 2017 11:12 am

if I try to compile this code I will get two errors, the first is that TheGunner as IObject do not exists, I suppose you have declared it in another portion of code. The second refers to the Enemies array wich you use without the index and brackets, but there aren't null references.

Can you send me all your script for helping me to help you?
0 x

jamisco
Superfighter
Superfighter
Posts: 67
Joined: Sun Nov 06, 2016 11:34 pm
Title: Da God
SFD Account: Jamisco
SFD Alias: Jamisco
Started SFD: either late 2015 or early 2016
Location: Somewhere in the east of the United states
Gender:
Age: 103

Post by jamisco » Tue Jun 27, 2017 8:28 pm

Due to the change in problem, I created a new post, which can be found here
0 x
Is it better to be feared or respected... please, is it too much to ask for both?

Post Reply