* Corrected description of scope and npc variables in script_commands.txt.

* Made temporary character string variables not have a limited length. (now all temporary string variables don't have limited length)
* Made temporary character variables reuse free positions.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11984 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
FlavioJS 2007-12-27 05:47:50 +00:00
parent 4dcf5bb0b9
commit b6c11a8282
6 changed files with 65 additions and 40 deletions

View File

@ -4,6 +4,10 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2007/12/27 2007/12/27
* Corrected description of scope and npc variables in script_commands.txt.
* Made temporary character string variables not have a limited length.
(now all temporary string variables don't have limited length)
* Made temporary character variables reuse free positions.
* Tweeked the declaration and initialization defines for vectors. * Tweeked the declaration and initialization defines for vectors.
* Made do_sockets leave the for loop as soon as the readable number of * Made do_sockets leave the for loop as soon as the readable number of
sockets returned by select is found. sockets returned by select is found.

View File

@ -4,7 +4,7 @@
//= A reference manual for the eAthena scripting language. //= A reference manual for the eAthena scripting language.
//= Commands are sorted depending on their functionality. //= Commands are sorted depending on their functionality.
//===== Version =========================================== //===== Version ===========================================
//= 3.10.20071122 //= 3.12.20071227
//========================================================= //=========================================================
//= 1.0 - First release, filled will as much info as I could //= 1.0 - First release, filled will as much info as I could
//= remember or figure out, most likely there are errors, //= remember or figure out, most likely there are errors,
@ -93,6 +93,8 @@
//= Updated guardianinfo and get-/setcastledata [ultramage] //= Updated guardianinfo and get-/setcastledata [ultramage]
//= 3.12.20071218 //= 3.12.20071218
//= Corrected various mistakes mentioned in bugreport:373 [ultramage] //= Corrected various mistakes mentioned in bugreport:373 [ultramage]
//= 3.12.20071227
//= Corrected description of scope and npc variables. [FlavioJS]
//========================================================= //=========================================================
This document is a reference manual for all the scripting commands and functions This document is a reference manual for all the scripting commands and functions
@ -495,12 +497,11 @@ local - local to the server
account - attached to the account of the character identified by RID account - attached to the account of the character identified by RID
character - attached to the character identified by RID character - attached to the character identified by RID
npc - attached to the NPC npc - attached to the NPC
scope - attached to the scope of the instance
Extent can be: Extent can be:
permanent - Permanent NPC variables exist while the server is running. permanent - They still exist when the server resets.
Others still exist when the server resets. temporary - They cease to exist when the server resets.
temporary - Temporary NPC variables exist while the script instance is running.
Others cease to exist when the server resets.
Prefix: scope and extent Prefix: scope and extent
nothing - A permanent variable attached to the character, the default nothing - A permanent variable attached to the character, the default
@ -515,11 +516,16 @@ nothing - A permanent variable attached to the character, the default
"$@" - A global temporary variable. "$@" - A global temporary variable.
This is important for scripts which are called with no RID This is important for scripts which are called with no RID
attached, that is, not triggered by a specific character object. attached, that is, not triggered by a specific character object.
"." - A variable that exists on the NPC as long as the server is running. "." - A NPC variable.
They are only accessible from inside the NPC or by calling They exist in the NPC and dissapear when the server restarts or the
npc is reloaded. Can be accessed from inside the NPC or by calling
'getvariableofnpc'. 'getvariableofnpc'.
".@" - A temporary variable that exists until the script instance ends. ".@" - A scope variable.
They are only accessible in that NPC instance. They are unique to the instance and scope. Each instance has it's
own scope that ends when the script ends. Calling a function with
callsub/callfunc starts a new scope, returning from the function
ends it. When a scope ends, it's variables are converted to values
('return .@var;' returns a value, not a reference).
"#" - A permanent local account variable. "#" - A permanent local account variable.
They are stored with all the account data in "save\accreg.txt" in They are stored with all the account data in "save\accreg.txt" in
TXT versions and in the SQL versions in the 'global_reg_value' TXT versions and in the SQL versions in the 'global_reg_value'
@ -546,10 +552,10 @@ Examples:
$name$ - permanent global string variable $name$ - permanent global string variable
$@name - temporary global integer variable $@name - temporary global integer variable
$@name$ - temporary global string variable $@name$ - temporary global string variable
.name - permanent npc integer variable .name - npc integer variable
.name$ - permanent npc string variable .name$ - npc string variable
.@name - temporary npc integer variable .@name - scope integer variable
.@name$ - temporary npc string variable .@name$ - scope string variable
#name - permanent local account integer variable #name - permanent local account integer variable
#name$ - permanent local account string variable #name$ - permanent local account string variable
##name - permanent global account integer variable ##name - permanent global account integer variable
@ -1473,7 +1479,7 @@ You can pass multiple arguments in a function call:
getarg(0) would be 5, getarg(1) would be 4 and getarg(2) would be 3. getarg(0) would be 5, getarg(1) would be 4 and getarg(2) would be 3.
Getarg has an optional argument since trunk r10773. Getarg has an optional argument since trunk r10773 and stable r10958.
If the target argument exists, it is returned. If the target argument exists, it is returned.
Otherwise, if <default_value> is present it is returned instead, Otherwise, if <default_value> is present it is returned instead,
if not the script terminates immediately. if not the script terminates immediately.

View File

@ -1671,6 +1671,10 @@ int map_quit(struct map_session_data *sd)
} }
if(sd->regstr) if(sd->regstr)
{ {
int i;
for( i = 0; i < sd->regstr_num; ++i )
if( sd->regstr[i].data )
aFree(sd->regstr[i].data);
aFree(sd->regstr); aFree(sd->regstr);
sd->regstr = NULL; sd->regstr = NULL;
sd->regstr_num = 0; sd->regstr_num = 0;

View File

@ -365,7 +365,7 @@ struct script_reg {
}; };
struct script_regstr { struct script_regstr {
int index; int index;
char data[256]; char* data;
}; };
struct status_change_entry { struct status_change_entry {

View File

@ -5898,15 +5898,19 @@ int pc_setreg(struct map_session_data* sd, int reg, int val)
ARR_FIND( 0, sd->reg_num, i, sd->reg[i].index == reg ); ARR_FIND( 0, sd->reg_num, i, sd->reg[i].index == reg );
if( i < sd->reg_num ) if( i < sd->reg_num )
// overwrite existing entry {// overwrite existing entry
sd->reg[i].data = val; sd->reg[i].data = val;
else { return 1;
// insert new entry }
ARR_FIND( 0, sd->reg_num, i, sd->reg[i].data == 0 );
if( i == sd->regstr_num )
{// nothing free, increase size
sd->reg_num++; sd->reg_num++;
RECREATE(sd->reg, struct script_reg, sd->reg_num); RECREATE(sd->reg, struct script_reg, sd->reg_num);
sd->reg[i].index = reg;
sd->reg[i].data = val;
} }
sd->reg[i].index = reg;
sd->reg[i].data = val;
return 1; return 1;
} }
@ -5939,27 +5943,37 @@ int pc_setregstr(struct map_session_data* sd, int reg, char* str)
ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].index == reg ); ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].index == reg );
if( i < sd->regstr_num ) if( i < sd->regstr_num )
{ {// found entry, update
if (str && strcmp(str,"")!=0) if( str == NULL || *str == '\0' )
safestrncpy(sd->regstr[i].data, str, sizeof(sd->regstr[i].data)); {// empty string
else { if( sd->regstr[i].data != NULL )
sd->regstr_num--; aFree(sd->regstr[i].data);
memcpy(&sd->regstr[i], &sd->regstr[sd->regstr_num], sizeof(sd->regstr[0])); sd->regstr[i].data = NULL;
RECREATE(sd->regstr, struct script_regstr, sd->regstr_num); }
else if( sd->regstr[i].data )
{// recreate
size_t len = strlen(str)+1;
RECREATE(sd->regstr[i].data, char, len);
memcpy(sd->regstr[i].data, str, len*sizeof(char));
}
else
{// create
sd->regstr[i].data = aStrdup(str);
} }
return 1; return 1;
} }
if (!str) return 1; if( str == NULL || *str == '\0' )
return 1;// nothing to add, empty string
sd->regstr_num++; ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].data == NULL );
RECREATE(sd->regstr, struct script_regstr, sd->regstr_num); if( i == sd->regstr_num )
if(sd->regstr==NULL){ {// nothing free, increase size
ShowFatalError("out of memory : pc_setreg\n"); sd->regstr_num++;
exit(EXIT_FAILURE); RECREATE(sd->regstr, struct script_regstr, sd->regstr_num);
} }
sd->regstr[i].index = reg; sd->regstr[i].index = reg;
safestrncpy(sd->regstr[i].data, str, sizeof(sd->regstr[i].data)); sd->regstr[i].data = aStrdup(str);
return 1; return 1;
} }

View File

@ -2268,11 +2268,8 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, char* name, voi
char* p; char* p;
struct linkdb_node** n; struct linkdb_node** n;
n = (ref) ? ref : (name[1] == '@') ? st->stack->var_function : &st->script->script_vars; n = (ref) ? ref : (name[1] == '@') ? st->stack->var_function : &st->script->script_vars;
p = linkdb_search(n, (void*)num); p = linkdb_erase(n, (void*)num);
if (p) { if (p) aFree(p);
linkdb_erase(n, (void*)num);
aFree(p);
}
if (str[0]) linkdb_insert(n, (void*)num, aStrdup(str)); if (str[0]) linkdb_insert(n, (void*)num, aStrdup(str));
} }
return 1; return 1;