Create new state machines with different automaton in a public
#1

PHP код:
forward SetTimerByTimes(functionsname[],timemin,timemax);
public 
SetTimerByTimes(functionsname[],timemin,timemax)
{
    new 
Times[3];
    
gettime(Times[0], Times[1], Times[2]);
    if((
Times[0]- timemin) > (Times[0]- timemax)){
        
newtimer SetTimerEx("Test",((Times[0] < timemin)?(((timemin-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)):(((24-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)+(timemin*60*60*1000))),false,"sii",functionsname,timemin,timemax);
        
state call:min;
    }else{
        
newtimer SetTimerEx("Test",((Times[0] < timemax)?(((timemax-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)):(((24-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)+(timemax*60*60*1000))),false,"sii",functionsname,timemin,timemax);
        
state call:max;
    }
    return 
1;

I want to create every Time when this stock-function is called a new state maschine with the name of the function
as automaton but it won't work i get still the same error
PHP код:
error 086unknown automaton "functionsname" 
i need that to call the different publics

PHP код:
forward Test(functionsname[],timemin,timemax);
public 
Test(functionsname[],timemin,timemax)<call:min>
{
    new 
Times[3];
    
gettime(Times[0], Times[1], Times[2]);
    
CallLocalFunction(functionsname,"");
    
state call:max;
    
newtimer SetTimerEx("Test",((Times[0] < timemax)?(((timemax-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)):(((24-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)+(timemax*60*60*1000))),false,"ii",timemin,timemax);
    return 
1;
}
public 
Test(functionsname[],timemin,timemax)<call:max>
{
    new 
Times[3];
    
gettime(Times[0], Times[1], Times[2]);
    
CallLocalFunction(functionsname,"");
    
state call:min;
    
newtimer SetTimerEx("Test",((Times[0] < timemin)?(((timemin-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)):(((24-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)+(timemin*60*60*1000))),false,"ii",timemin,timemax);
    return 
1;

PHP код:
SetTimerByTimes("btest",12,22); 
This publics with SetTimerEx
PHP код:
forward btest();
public 
btest()<call:min>
{
    
printf("Hallo");
    return 
1;
}
public 
btest()<call:max>
{
    
printf("By");
    return 
1;

i even know that this is a string but even i tried it with Makros but it still won't work.

Have everyone an idea to do this which is even efficient like using state
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
A better question is WHY? What are you trying to achieve? This seems like an instance of the "X-Y" problem - you have some problem "X" and you think you have a solution "Y", but you don't know how to do "Y" so you ask how. It would be better if you told us what the problem you were trying to solve was as it is highly likely that there is a different, better solution.

If not, could you at least rephrase your question as I have no idea what you actually mean - there are no stock functions in that code, I don't know what line gives the error you quoted, and your two "SetTimerEx" lines look identical. Actually, looking at that, why not just name the two "Test" functions something different from each other?
Ok Thank you ****** for answering.

I often ask for other solutions because i always remember for the statement of Einstein
"Problems can be never solved from the same level of thinking with which they were created."

I have an other solutions and it works




PHP код:
#define CalculateTime(%0,%1,%2,%3) (((%0-(%1+1))*60*60*1000) +((60-(%2+1))*60*1000)+((60-%3)*1000))
#define CalculateTimeToNextDay(%0,%1,%2,%3) (((24-(%1+1))*60*60*1000) +((60-(%2+1))*60*1000)+((60-%3)*1000)+(%0*60*60*1000))
#define pTime%0(%1) forward%0(id); public%0(id)
#if !defined MAX_TIMERS
    #define MAX_TIMERS 10
#endif
new bool:TimerVar[MAX_TIMERS char];
new 
TimerName[MAX_TIMERS][20];
forward SetTimerByTimes(functionsname[],timemin,timemaxid);
public 
SetTimerByTimes(functionsname[],timemin,timemaxid)
{
    new 
Times[3], var;
    
Times[0] = 16;
    
Times[1] = 59;
    
Times[2] = 0;
    
//gettime(Times[0], Times[1], Times[2]);
    
if((Times[0]- timemin) > (Times[0]- timemax) && (Times[0]- timemin) < 0){
        
SetTimerEx("TimerKonfig",((Times[0] < timemin)?CalculateTime(timemin,Times[0], Times[1], Times[2]):CalculateTimeToNextDay(timemin,Times[0], Times[1], Times[2])),false,"siii",functionsname,timemin,timemax,id);
        
TimerVar{id} = true;
        var = (
Times[0] < timemin)?CalculateTime(timemin,Times[0], Times[1], Times[2]):CalculateTimeToNextDay(timemin,Times[0], Times[1], Times[2]);
        
printf("Time %d time from start timer %d %d %d",var,Times[0], Times[1], Times[2]);
        
strins(TimerName[id],functionsname,0);
    }else{
        
SetTimerEx("TimerKonfig",((Times[0] < timemax)?CalculateTime(timemax,Times[0], Times[1], Times[2]):CalculateTimeToNextDay(timemax,Times[0], Times[1], Times[2])),false,"siii",functionsname,timemin,timemax,id);
        
TimerVar{id} = false;
        
strins(TimerName[id],functionsname,0);
    }
    return 
id;
}
forward TimerKonfig(functionsname[],timemin,timemaxid);
public 
TimerKonfig(functionsname[],timemin,timemaxid)
{
    new 
Times[3];
    
gettime(Times[0], Times[1], Times[2]);
    if(
TimerVar[id]){
        
CallRemoteFunction(TimerName[id],"d",id);
        
SetTimerEx("Test",((Times[0] < timemin)?(((timemin-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)):(((24-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)+(timemin*60*60*1000))),false,"ii",timemin,timemax);
        
TimerVar{id} = false;
    }else{
        
CallLocalFunction(TimerName[id],"d",id);
          
SetTimerEx("Test",((Times[0] < timemin)?(((timemin-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)):(((24-(Times[0]+1))*60*60*1000) +((60-(Times[1]+1))*60*1000)+((60-Times[2])*1000)+(timemin*60*60*1000))),false,"ii",timemin,timemax);
        
TimerVar{id} = true;
    }
    return 
1;

but the timer has an delay from around 1 Minute per hour.

But now to my first problem.
I wanted to use state for the called function.
but now when i call the functions i use an if statement
PHP код:
SetTimerByTimes("btest",17,20,0); 
PHP код:
pTime btest()
{
    if(
TimerVar{id}){
        
printf("btest1");
    }else{
        
printf("btest2");
    }
    return 
1;

But i wanted to use state and made it so

PHP код:
pTime btest()<btest:min>
{
    return 
1;

PHP код:
pTime btest()<btest:max>
{
    return 
1;

Where is the problem there?
I think that it is not possibel to create a new state maschine with the name of the function in
the example
PHP код:
public SetTimerByTimes(functionsname[],timemin,timemaxid)
{
....
state functionsname:min
that if i use my function SetTimerByTimes. it have to create the automaton with the name of this string

PHP код:
SetTimerByTimes("btest",17,20,0); 
PHP код:
public SetTimerByTimes(functionsname[],timemin,timemaxid)
{
....
state btest:min
I hope it was now evident and yes I know that my first explanation was very difficult to understand, because I didn't know exactly what I want.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)