Help with Syntax Errors

Draganizer

Member
Reaction score
1
I need help fixing two syntax errors. they are in red bold. Thanks in advance!


Line 9342 Function inside struct?
// Trigger: Deactivate Mode Selection
//===========================================================================
function Trig_Deactivate_Mode_Selection_Actions takes nothing returns nothing
call DisplayTimedTextToForce( GetPlayersAll(), 10.00, "TRIGSTR_2386" )
call DisableTrigger( gg_trg_Choose_Mode )
call DisableTrigger( gg_trg_Mode_Ap )
call DisableTrigger( gg_trg_Mode_Ar )
call DisableTrigger( gg_trg_Mode_Pm )
call DisableTrigger( gg_trg_Mode_Sm )
call DisableTrigger( gg_trg_Mode_Om )
call DisableTrigger( gg_trg_Mode_Nr )
endfunction

//===========================================================================
function InitTrig_Deactivate_Mode_Selection takes nothing returns nothing
set gg_trg_Deactivate_Mode_Selection = CreateTrigger( )
call TriggerRegisterTimerEventSingle( gg_trg_Deactivate_Mode_Selection, 20.00 )
call TriggerAddAction( gg_trg_Deactivate_Mode_Selection, function Trig_Deactivate_Mode_Selection_Actions )
endfunction

//===========================================================================

and Line 8799: struct declaration

// Trigger: Command
//
// Default melee game initialization for all players
//===========================================================================
//TESH.scrollpos=180
//TESH.alwaysfold=0
//! zinc
library Command requires Table,Ascii
{

constant string ARG_DELIMITER = " ";

public type commandFunc extends function(Args);

private function msg_error (string msg)
{
DisplayTimedTextToPlayer(GetLocalPlayer(), .0, .0, 60., "|cffCC33CC" + "CommandParser Error: " + msg);
}

// Struct to store/typecheck/typecast values
public struct ArgsValue
{
private static string DEF_BOOL_TRUE[], DEF_BOOL_FALSE[];
private static constant integer DEF_BOOL_SIZE = 4;

public static string DEF_PLAYERCOLORS[];
private static constant integer DEF_PLAYERCOLORS_SIZE = 15;

private static integer MIN_PLAYER_INDEX = 1, MAX_PLAYER_INDEX = 12;

private string source;

// Returns the source string
method getStr ()-> string
{
return source;
}

// Checks to see if source can be interpreted as a boolean.
// Returns true if source can be found in the array of "true" definitions, false if not.
method isBool ()-> boolean
{
integer i;
string s = StringCase(source, false);
for (i=0; i<DEF_BOOL_SIZE; i+=1)
{
if (s==DEF_BOOL_TRUE || s==DEF_BOOL_FALSE)
return true;
}
return false;
}

// Returns a boolean value interpreted from source.
// Returns true if source is found to be a "true" value, false otherwise.
method getBool ()-> boolean
{
integer i;
string s = StringCase(source, false);
for (i=0; i<DEF_BOOL_SIZE; i+=1)
{
if (s==DEF_BOOL_TRUE)
return true;
}
return false;
}


// Checks to see if source can be interpreted as an integer.
// Returns true if it only contains number characters, false if not.
method isInt ()-> boolean
{
string s = source;
integer ascii;
while (s!="")
{
ascii = Char2Ascii(SubString(s, 0, 1));
s = SubString(s, 1, StringLength(s));
if (!(ascii>=48 && ascii<=57)) // 0-9
return false;
}
return true;
}

// Returns source as an integer.
// Returns 0 if source can't be interpreted as an integer.
method getInt ()-> integer
{
return S2I(source);
}

// Checks to see if source can be interpreted as a real.
// Returns true if source only contains number characters, and at max 1 decimal point.
method isReal ()-> boolean
{
string s = source;
integer ascii, decimal_count = 0;
while (s!="")
{
ascii = Char2Ascii(SubString(s, 0, 1));
s = SubString(s, 1, StringLength(s));
if (ascii==46) // decimal point
decimal_count+=1;
else if (!(ascii>=48 && ascii<=57)) // 0-9
return false;
}
return (decimal_count<=1); // no self respecting real number has more than one decimal point
}

// Returns source as a real.
// Returns 0.000 if source can't be interpreted as a real.
method getReal ()-> real
{
return S2R(source);
}

// Checks to see if source can be interpreted as a player.
// Returns true if source matches a player number 1-12, or 0-11 if START_PLAYER_NUMBERS_AT_ZERO is true.
// Returns true if source matches a player color.
// Returns true if source matches a player's name, or is a substring at the start of a player's name.
method isPlayer ()-> boolean
{
integer i, length;
string s = StringCase(source, false);

// check if source is a player number
if (isInt())
{
i = getInt();
if (i>=MIN_PLAYER_INDEX && i<=MAX_PLAYER_INDEX)
return true;
}
// check if source is a player color
for (i=0; i<DEF_PLAYERCOLORS_SIZE; i+=1)
{
if (s==DEF_PLAYERCOLORS)
return true;
}
// check to see if source matches or starts a player name
length = StringLength(s);
for (i=0; i<bj_MAX_PLAYERS; i+=1)
{
if (s==SubString(StringCase(GetPlayerName(Player(i)), false), 0, length))
return true;
}
return false;
}

// Returns source as a player.
// Returns null if source can not be interpreted as a player.
method getPlayer ()-> player
{
integer i, j, length;
string s = StringCase(source, false);

// check if source is a player number
if (isInt())
{
i = getInt();
if (i>=MIN_PLAYER_INDEX && i<=MAX_PLAYER_INDEX)
return Player(i-MIN_PLAYER_INDEX);
}

if (s==DEF_PLAYERCOLORS[12]) // cyan -> teal
{
s = DEF_PLAYERCOLORS[2];
}
if (s==DEF_PLAYERCOLORS[13]) // grey -> gray
{
s = DEF_PLAYERCOLORS[8];
}
// check if source is a player color
for (i=0; i<bj_MAX_PLAYERS; i+=1)
{
if (s==DEF_PLAYERCOLORS)
{
for (j=0; j<bj_MAX_PLAYERS; j+=1)
{
if (GetPlayerColor(Player(j))==ConvertPlayerColor(i))
{
return Player(j);
}
}
}
}

// Check if source matches or starts a player name
length = StringLength(s);
for (i=0; i<bj_MAX_PLAYERS; i+=1)
{
if (s==SubString(StringCase(GetPlayerName(Player(i)), false), 0, length))
return Player(i);
}

return null;
}

// Deallocate this struct and it's child.
method destroy ()
{
deallocate();
}

// Allocate thistype struct.
static method create (string s)-> thistype
{
thistype vi = thistype.allocate();
vi.source = s;
return vi;
}

// Initialize data
private static method onInit ()
{
// stole these definitions from Prozix :)
DEF_BOOL_TRUE[0] = "true";
DEF_BOOL_TRUE[1] = "yes";
DEF_BOOL_TRUE[2] = "1";
DEF_BOOL_TRUE[3] = "on";
DEF_BOOL_FALSE[0] = "false";
DEF_BOOL_FALSE[1] = "no";
DEF_BOOL_FALSE[2] = "0";
DEF_BOOL_FALSE[3] = "off";

// player color strings
DEF_PLAYERCOLORS[0] = "red";
DEF_PLAYERCOLORS[1] = "blue";
DEF_PLAYERCOLORS[2] = "teal";
DEF_PLAYERCOLORS[3] = "purple";
DEF_PLAYERCOLORS[4] = "yellow";
DEF_PLAYERCOLORS[5] = "orange";
DEF_PLAYERCOLORS[6] = "green";
DEF_PLAYERCOLORS[7] = "pink";
DEF_PLAYERCOLORS[8] = "gray";
DEF_PLAYERCOLORS[9] = "lightblue";
DEF_PLAYERCOLORS[10] = "darkgreen";
DEF_PLAYERCOLORS[11] = "brown";

// extra spellings..
DEF_PLAYERCOLORS[12] = "cyan";
DEF_PLAYERCOLORS[13] = "grey";

MIN_PLAYER_INDEX = 0;
MAX_PLAYER_INDEX = 11;
}
}

// List of ArgsValue structs
public struct Args
{
private thistype last;
private thistype next;
private ArgsValue arg;

private integer list_size;
method size ()-> integer { return list_size; }

method operator[] (integer index)-> ArgsValue
{
thistype a = this;
integer i = 0;
if (index<0 || index>size())
{
debug msg_error("Attempt to access Args element out of bounds.");
return 0;
}
while (i<=index)
{
a = a.next;
i +=1;
}
return a.arg;
}

// Allocate a new node, add it to the list and set it's value.
method add_arg (string s)
{
thistype a = thistype.allocate();
last.next = a;
last = a;
a.next = -1;
a.arg = ArgsValue.create(s);
list_size += 1;
}

// Deallocate this struct, and members of it's list.
method destroy ()
{
thistype a = this, b;
while (a.next!=-1)
{
a = a.next;
b = a;
a.deallocate();
a = b;
}
deallocate();
}

// Allocate thistype and initialize variables.
static method create ()-> thistype
{
thistype a = thistype.allocate();
a.last = a;
a.next = -1;
a.list_size = 0;
return a;
}
}



private struct Func
{
private thistype next;
private thistype last;
private integer lenght;
private commandFunc func;

method Count()->integer { return lenght; }

// Ejecuta todas las funciones
method Execute (Args args)
{
thistype temp = this;
while(temp.next!=-1)
{
temp = temp.next;
temp.func.execute(args);
}
}

// Remueve una funcion determinada
method RemoveFunc (commandFunc toRemove)
{
thistype prev, temp = this;
while (temp.next!=-1)
{
prev = temp;
temp = temp.next;
if (temp.func==toRemove)
{
prev.next = temp.next;
temp.deallocate();
lenght -= 1;
return;
}
}
debug BJDebugMsg("|cffCC33CC"+"Command error: removiendo una funcion no existente!");
}

// Agrega una funcion determinada
method AddFunc (commandFunc toAdd)
{
thistype temp = this;
// Vemos primero si ya existe
while (temp.next!=-1)
{
temp = temp.next;
if (temp.func == toAdd)
{
debug BJDebugMsg("|cffCC33CC"+"Command error: agregando funcion repetida a un commando!");
return;
}
}
// A duplicate was not found, allocate the node
temp = thistype.allocate();
last.next = temp;
last = temp;
temp.next = -1;
temp.func = toAdd;
lenght += 1;
}

// Deallocate this struct, and members of it's list.
method destroy ()
{
thistype a = this, b;
while(a.next!=-1)
{
a = a.next;
b = a;
a.deallocate();
a = b;
}
deallocate();
}

// Allocate thistype and initialize variables.
static method create ()-> thistype
{
thistype this = thistype.allocate();
last = this;
next = -1;
lenght = 0;
return this;
}
}

public struct Command
{
trigger trig;
string cmd;
static Table table;

private Func funcs;
private boolean player_permissions[12];

static method operator[] (string s) -> thistype
{
if (table.exists(StringHash(s)))
return table[StringHash(s)];
return create(s);
}

private static method parse (Args args, string input)
{
integer i = 0;
while(i<StringLength(input))
{
if (SubString(input, i, i+1)==ARG_DELIMITER)
{
if (i>0) // there's something before the delimiter
{
args.add_arg(SubString(input, 0, i));
}
input = SubString(input, i+1, StringLength(input));
i = -1;
}
i += 1;
}
if (i>0) // there's stuff left
{
args.add_arg(input);
}
}

private static method onChat () -> boolean
{
string input = GetEventPlayerChatString();
string command = GetEventPlayerChatStringMatched();
thistype this;
Args args;

// el comando fue encontrado pero no era lo primero
if (SubString(input, 0, StringLength(command))!=command)
return false;

this = table[StringHash(command)];

// the player is not allowed to use this command, exit
if (this.player_permissions[GetPlayerId(GetTriggerPlayer())]==false)
return false;

// argumentos ingresados
input = SubString(input,StringLength(command)+StringLength(ARG_DELIMITER),StringLength(input));

args = Args.create();
args.add_arg(command);
parse(args, input);
this.funcs.Execute(args);
args.destroy();

return false;
}

private static method create (string s) -> thistype
{
thistype this = allocate();
integer index = 0;

this.trig = CreateTrigger();
for(index=0; index<11; index+=1)
{
TriggerRegisterPlayerChatEvent(this.trig, Player(index), s, false);
this.player_permissions[index] = true;
}
TriggerAddCondition(this.trig,function thistype.onChat);

this.funcs = Func.create();
this.cmd = s;
table[StringHash(s)] = this;

return this;
}

method destroy ()
{
table.flush(StringHash(cmd));
DisableTrigger(trig);
DestroyTrigger(trig);
funcs.destroy();
deallocate();
}

method remove () { destroy(); }

// enable/disable el comando
method enable (boolean flag)
{
if (flag) EnableTrigger(trig);
else DisableTrigger(trig);
}

// Retorna si el comando esta activado o desactivado
method isEnabled ()-> boolean
{
return IsTriggerEnabled(trig);
}

// setea un permiso para todos los players
method setPermissionAll (boolean flag)
{
integer i;
for (i=0; i<bj_MAX_PLAYERS; i+=1)
{
player_permissions = flag;
}
}

// setea el permiso para un player especifico
method setPermission (player p, boolean flag)
{
player_permissions[GetPlayerId(p)] = flag;
}

// obtiene el permiso de un player especifico
method getPermission (player p)-> boolean
{
return player_permissions[GetPlayerId(p)];
}

// registra una funcion al comando
method Register (commandFunc func)
{
if (func == 0)
debug BJDebugMsg("|cffCC33CC"+"Command error: registrando funcion nula! "+cmd);
else
funcs.AddFunc(func);
}

// elimina una funcion del comando
method Unregister (commandFunc func)
{
if (func == 0)
debug BJDebugMsg("|cffCC33CC"+"Command error: eliminando funcion nula! "+cmd);
else
{
funcs.RemoveFunc(func);
if (funcs.Count()==0)
destroy();
}
}

// Inicia la table
private static method onInit () { table = Table.create(); }


}
 

jackall

You can change this now in User CP.
Reaction score
37
use
JASS:
 tags, 1st problem is you can&#039;t use functions inside of structs, only methods(that means you just have to replace &quot;function&quot; with &quot;method&quot;, then when you want to call that method you do it as such: &lt;name of struct&gt; . &lt;name of method&gt; and then pass arguments to it like you would do with an ordinary function
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
JASS:
static method Example takes nothing returns nothing //is the same as:
function Example takes nothing returns nothing

method Example takes nothing returns nothing //is the same as:
function Example takes integer this returns nothing

//call examples:
//static method:
call Struct.Example()
//non-static method:
call Struct(0).Example()
//where 0 = the argument &quot;this&quot;


PS. PLEASE INDENT RIGHT
and [noparse]
JASS:
>
Code said:
[/noparse]

EDIT:
I just realized the issue there, you probably have a struct with no [ljass]endstruct[/ljass] so it thinks everything below it is inside th e struct...
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top