What this checks?

Dastgir

Core Developer
Messages
3,805
Points
0
Discord
Dastgir#1460
IRC Nickname
Dastgir
Github
dastgirp
Emulator
Client Version
2019-02-28 RE
int run_func(struct script_state *st){ struct script_data* data; int i,start_sp,end_sp,func; end_sp = st->stack->sp;// position after the last argument for( i = end_sp-1; i > 0 ; --i ) if( st->stack->stack_data.type == C_ARG ) break; if( i == 0 ) { ShowError("script:run_func: C_ARG not found. please report this!!!n"); st->state = END; script_reportsrc(st); return 1; } start_sp = i-1;// C_NAME of the command st->start = start_sp; st->end = end_sp; data = &st->stack->stack_data[st->start]; if( data->type == C_NAME && script->str_data[data->u.num].type == C_FUNC ) func = data->u.num; else { ShowError("script:run_func: not a buildin command.n"); script_reportdata(data); script_reportsrc(st); st->state = END; return 1; } if( script->config.warn_func_mismatch_argtypes ) { script_check_buildin_argtype(st, func); } if(script->str_data[func].func){ if (!(script->str_data[func].func(st))){ //Report error script_reportsrc(st); } } else { ShowError("script:run_func: '%s' (id=%d type=%s) has no C function. please report this!!!n", script->get_str(func), func, script_op2name(script->str_data[func].type)); script_reportsrc(st); st->state = END; } // Stack's datum are used when re-running functions [Eoe] if( st->state == RERUNLINE ) return 0; script->pop_stack(st, st->start, st->end); if( st->state == RETFUNC ) {// return from a user-defined function struct script_retinfo* ri; int olddefsp = st->stack->defsp; int nargs; script->pop_stack(st, st->stack->defsp, st->start);// pop distractions from the stack if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp-1].type != C_RETINFO ) { ShowWarning("script:run_func: return without callfunc or callsub!n"); script_reportsrc(st); st->state = END; return 1; } script->free_vars( st->stack->var_function ); ri = st->stack->stack_data[st->stack->defsp-1].u.ri; nargs = ri->nargs; st->pos = ri->pos; st->script = ri->script; st->stack->var_function = ri->var_function; st->stack->defsp = ri->defsp; memset(ri, 0, sizeof(struct script_retinfo)); script->pop_stack(st, olddefsp-nargs-1, olddefsp);// pop arguments and retinfo st->state = GOTO; } return 0;}
Above is code of run_func()

I want to ask what this checks for

 if(script->str_data[func].func){ if (!(script->str_data[func].func(st))){ //Report error script_reportsrc(st); } }

because its the part that goes to script_reportsrc and gives some [Debug]: Source (NPC) Invisible on map

 
Last edited by a moderator:
Code:
 if(script->str_data[func].func){// <= check if the pointer isn't null        if (!(script->str_data[func].func(st))){ //run the function            script_reportsrc(st);//if the function returns false, dump the errors        }    }
 
if(script->str_data[func].func){// <= check if the pointer isn't null if (!(script->str_data[func].func(st))){ //run the function script_reportsrc(st);//if the function returns false, dump the errors } }
But with custom script command, it always returns false and dumps the error(but script is executed.).Should custom function return 1?

 
Last edited by a moderator:
Code:
if(script->str_data[func].func){// <= check if the pointer isn't null        if (!(script->str_data[func].func(st))){ //run the function            script_reportsrc(st);//if the function returns false, dump the errors        }    }
But with custom script command, it always returns false and dumps the error(but script is executed.).Should custom function return 1?
the custom script is at fault then. shouldn't return 1 nor 0, its true or false.
 
Back
Top