summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-06-21 21:46:24 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-06-21 21:46:24 +0000
commit8e67f78bec84c8d3d6c9331ec9409d7ed1e94233 (patch)
treecbed075dc8a9fdaafb1a729c1a4a31c1f9ca8137 /src/map/script.c
parente53ce7ef5610a1fb1dc3597e56c6610e026828a5 (diff)
downloadhercules-8e67f78bec84c8d3d6c9331ec9409d7ed1e94233.tar.gz
hercules-8e67f78bec84c8d3d6c9331ec9409d7ed1e94233.tar.bz2
hercules-8e67f78bec84c8d3d6c9331ec9409d7ed1e94233.tar.xz
hercules-8e67f78bec84c8d3d6c9331ec9409d7ed1e94233.zip
* Extended script command 'set' to return the variable reference (topic:190602).
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12871 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/map/script.c b/src/map/script.c
index b1f6371ec..6026345b7 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -4673,27 +4673,36 @@ BUILDIN_FUNC(input)
return 0;
}
-/*==========================================
- * 変数設定
- *------------------------------------------*/
+/// Sets the value of a variable.
+/// The value is converted to the type of the variable.
+///
+/// set(<variable>,<value>) -> <variable>
BUILDIN_FUNC(set)
{
- TBL_PC *sd=NULL;
- int num=st->stack->stack_data[st->start+2].u.num;
- char *name=str_buf+str_data[num&0x00ffffff].str;
- char prefix=*name;
- char postfix=name[strlen(name)-1];
+ TBL_PC* sd = NULL;
+ struct script_data* data;
+ int num;
+ char* name;
+ char prefix;
+ char postfix;
- if( !data_isreference(script_getdata(st,2)) ){
+ data = script_getdata(st,2);
+ if( !data_isreference(data) )
+ {
ShowError("script:set: not a variable\n");
script_reportdata(script_getdata(st,2));
st->state = END;
return 1;
}
- if(not_server_variable(prefix))
+ num = reference_getuid(data);
+ name = reference_getname(data);
+ prefix = *name;
+ postfix = (*name ? name[strlen(name)-1] : '\0');
+
+ if( not_server_variable(prefix) )
{
- sd=script_rid2sd(st);
+ sd = script_rid2sd(st);
if( sd == NULL )
{
ShowError("script:set: no player attached for player variable '%s'\n", name);
@@ -4701,15 +4710,18 @@ BUILDIN_FUNC(set)
}
}
- if( postfix=='$' ){
- // 文字列
- const char *str = script_getstr(st,3);
+ if( postfix == '$' )
+ {// string variable
+ const char* str = script_getstr(st,3);
set_reg(st,sd,num,name,(void*)str,script_getref(st,2));
- }else{
- // 数値
+ }
+ else
+ {// integer variable
int val = script_getnum(st,3);
set_reg(st,sd,num,name,(void*)val,script_getref(st,2));
}
+ // return a copy of the variable reference
+ script_pushcopy(st,2);
return 0;
}