Xavier Arias
Xavier Arias

Reputation: 164

NetLogo custom extension command parameters error

I'm getting a problem with a reporter from a custom extension "myextension". I'm using NetLogo v.5.0.5.

Here's the code of the Java class reporter:

public class DoActionPrimitive extends DefaultReporter {

    @Override
    public Syntax getSyntax() {
        return Syntax.commandSyntax(
                new int[]{
                    Syntax.WildcardType(), // Platform
                    Syntax.StringType(),   // Action
                    Syntax.ListType()},    // Parameters
                Syntax.WildcardType());
    }

    public Object report(Argument[] args, Context context)
        throws LogoException, ExtensionException {

       // Reporter code
    }
}

And here's the code which gives a NetLogo compilation error:

extensions [myextension]

globals [platform]

turtles-own [logged-in?]

to setup
  clear-all
  reset-ticks
  create-turtles population 
  set platform myextension:create "Platform"
  ask turtles [ set logged-in? login ]
end

to-report login 
  report myextension:do-action platform "login" ["test-user" "123456"]
end

The NetLogo code tab gives a syntax error on the line :

report myextension:do-action platform "login" ["test-user" "123456"]

with the message:

"MYEXTENSION:DO-ACTION expected 8191 inputs, any input, a string and a list."

I guess something is wrong with the reporter syntax, maybe is not possible to have a WildcardType mixed with other parameters. I've also tried switching the first and second parameters, so having StringType before WildcardType but the error is the same but switching the parameters in the error message.

Why NetLogo expects 8191 inputs before my specified syntax inputs?

Thanks!

Upvotes: 2

Views: 73

Answers (1)

Bryan Head
Bryan Head

Reputation: 12580

You're using Syntax.commandSyntax which is only for commands. You want Syntax.reporterSyntax. Assuming Syntax.WildcardType() was meant to be your return type and you want the reporter to be runnable by any agent, you can just change Syntax.commandSyntax to Syntax.reporterSyntax I believe. That invokes this implementation of reporterSyntax.

The reason you were getting that error message (if you're curious) is because your code was calling this implementation of commandSyntax. The second parameter is then interpreted as the default number of arguments of the command (it's intended to be used with variadic commands). Types in NetLogo are numbers where each binary digit corresponds to some basic type. The number has 1s for all the types that are allowed and 0s for those that are not in its binary representation. So the basic types (NumberType, StringType, etc) have a 1 in exactly one digit. WildcardType is supposed to be anything, so it should have 1s in all digits that correspond to that type. Its binary representation is 1111111111111, which in decimal is 8191, the number from the error message.

Upvotes: 2

Related Questions