[Problem] timed_event_p_proc

Discussion in 'Fallout General Modding' started by fffffffff, Nov 23, 2019.

  1. fffffffff

    fffffffff First time out of the vault

    19
    Mar 20, 2017
    Hello I'm banana programmer and I've got huge problem.

    I need to have timed_event_p_proc repeated over and over and i want it repeated for example 1 time per second so basically it sounds like:
    Code:
    procedure map_enter_p_proc begin
        add_timer_event(self_obj,0,0);
    end
    
    procedure timed_event_p_proc begin
        if (fixed_param==0) then begin
            call repeatable_procedure;
            add_timer_event(self_obj,game_ticks(1),0);
        end
    end
    And it looks like it works but when I save the game and load it back, it executes 2 times more, again and again save/load X time more. And when I exit the map and go back to my map it executes fine and beautiful again but this saving/loading game breaks everything.
     
  2. Lexx

    Lexx Background Radiant
    Moderator Modder

    Apr 24, 2005
    Add a variable OR if not(game_loaded) then add_timer_event...

    PS: Why repeat it so often? If it's a critter, you might as well just put the code into the critter_p_proc.
     
    • [Rad] [Rad] x 1
  3. fffffffff

    fffffffff First time out of the vault

    19
    Mar 20, 2017
    Then with "if not(game_loaded)" add_timer_event doesn't execute timed_event_p_proc. I will publish whole code:

    Code:
    #include "..\headers\define.h"
    
    #define NAME                    SCRIPT_MGZ_LGHT
    
    #include "..\headers\command.h"
    #include "..\headers\ModReact.h"
    
    
    procedure start;
    procedure map_enter_p_proc;
    procedure map_exit_p_proc;
    procedure timed_event_p_proc;
    
    procedure start begin
    end
    
    procedure map_enter_p_proc begin
        if map_first_run and random(1,3) == 1 then set_obj_visibility(self_obj,true); else set_obj_visibility(self_obj,false);
        if (not(game_loaded)) then add_timer_event(self_obj,random(game_ticks(1),game_ticks(75)),0);
    end
    
    procedure map_exit_p_proc begin
    end
    
    variable counter;
    procedure timed_event_p_proc begin
    
        if (fixed_param==0) then begin
       
            if counter == 0 then begin
               
                set_obj_visibility(self_obj,false);
                counter++;
                add_timer_event(self_obj,1,0);
                display_msg("executing");
                if global_var(GVAR_MAGAZINE_REPAIRED_GENERATOR) == 0 then add_timer_event(self_obj,random(game_ticks(3),game_ticks(75)),0); else set_obj_visibility(self_obj,false);
               
            end  
    
            else if counter == 1 then begin
               
                set_obj_visibility(self_obj,true);
                counter++;
                add_timer_event(self_obj,15,0);
               
            end  
           
            else if counter == 2 then begin
               
                set_obj_visibility(self_obj,false);
                counter++;
                add_timer_event(self_obj,1,0);
               
            end  
           
            else if counter == 3 then begin
               
                set_obj_visibility(self_obj,true);
                counter++;
                add_timer_event(self_obj,5,0);
               
            end  
           
            else if counter == 4 then begin
               
                set_obj_visibility(self_obj,false);
                counter++;
                add_timer_event(self_obj,1,0);
               
            end  
           
            else if counter == 5 then begin
               
                set_obj_visibility(self_obj,true);
                counter++;
                add_timer_event(self_obj,5,0);
               
            end  
           
            else if counter == 6 then begin
               
                set_obj_visibility(self_obj,false);
                counter++;
                add_timer_event(self_obj,1,0);
               
            end  
           
            else if counter == 7 then begin
               
                set_obj_visibility(self_obj,true);
                counter++;
                add_timer_event(self_obj,5,0);
               
            end  
           
            else if counter == 8 then begin
               
                set_obj_visibility(self_obj,false);
                counter++;
                add_timer_event(self_obj,1,0);
               
            end  
           
            else if counter == 9 then begin
               
                if random(1,3) == 1 then set_obj_visibility(self_obj,true); else set_obj_visibility(self_obj,false);
                counter:=0;
               
            end
       
        end
    
    end
    Don't laugh please. This script is assigned to scenery object. It's just lighting hex. I wanted to create effect of flickering lighting which will be fixed with GVAR set to 1.
     
  4. NovaRain

    NovaRain Casual Modder Modder

    Mar 10, 2007
    You can try to add a "rm_fixed_timer_event(self_obj, 0);" line right after if (fixed_param==0) then begin.
     
    • [Rad] [Rad] x 1
  5. fffffffff

    fffffffff First time out of the vault

    19
    Mar 20, 2017
    But then my script stops repeating over and over.
     
  6. NovaRain

    NovaRain Casual Modder Modder

    Mar 10, 2007
    It seems you miss one add_timer_event() for counter == 9 ?
     
    Last edited: Nov 24, 2019
  7. fffffffff

    fffffffff First time out of the vault

    19
    Mar 20, 2017
    No, It's in counter == 0. But no worries. Lexx gave me an idea:

    Code:
    procedure map_enter_p_proc begin
    if local_var(LVAR_TimedEvent_Session) == 0 then set_local_var(LVAR_TimedEvent_Session,100);
        inc_local_var(LVAR_TimedEvent_Session);
        add_timer_event(self_obj,random(game_ticks(2),game_ticks(75)),local_var(LVAR_TimedEvent_Session));
    end
    
    procedure timed_event_p_proc begin
    
        if (fixed_param==local_var(LVAR_TimedEvent_Session)) then begin
    
            if counter == 0 then begin
             
                set_obj_visibility(self_obj,false);
                counter++;
                add_timer_event(self_obj,1,local_var(LVAR_TimedEvent_Session));
                display_msg("executing");
                if global_var(GVAR_MAGAZINE_REPAIRED_GENERATOR) == 0 then add_timer_event(self_obj,random(game_ticks(3),game_ticks(75)),local_var(LVAR_TimedEvent_Session)); else set_obj_visibility(self_obj,false);
             
            end  
    
            else if counter == 1 then begin
             
                set_obj_visibility(self_obj,true);
                counter++;
                add_timer_event(self_obj,15,local_var(LVAR_TimedEvent_Session));
             
            end
    
    ...
    
            else if counter == 8 then begin
             
                set_obj_visibility(self_obj,false);
                counter++;
                add_timer_event(self_obj,1,local_var(LVAR_TimedEvent_Session));
             
            end  
         
            else if counter == 9 then begin
             
                if random(1,3) == 1 then set_obj_visibility(self_obj,true); else set_obj_visibility(self_obj,false);
                counter:=0;
             
            end
     
        end
    
    end
    Now, it works perfectly. Thank you guys.
     
  8. Lexx

    Lexx Background Radiant
    Moderator Modder

    Apr 24, 2005
    Why do you need all these counter? As far as I can tell, you just want to flick the light on and off? This could be done in like... I don't know, 10 lines max?

    /edit: Ok I needed 20 lines, but still...
    /edit2: Added the gvar check to keep the light on.
    Code:
    variable light_state;
    
    procedure map_enter_p_proc begin
       if (local_var(LVAR_TimedEvent_Session) == 0) then begin
          set_local_var(LVAR_TimedEvent_Session, 1);
          add_timer_event(self_obj, game_ticks(random(2,75)), 1);
       end
    end
    
    procedure map_update_p_proc begin
       if (global_var(GVAR_MAGAZINE_REPAIRED_GENERATOR) > 0) then
          set_obj_visibility(self_obj, true);
    end
    
    procedure timed_event_p_proc begin
       if ((fixed_param == 1) and (global_var(GVAR_MAGAZINE_REPAIRED_GENERATOR) == 0)) then begin
          if (light_state == 0) then begin
             light_state := 1;
             set_obj_visibility(self_obj, true);
          end
          else begin
             light_state := 0;
             set_obj_visibility(self_obj, false);
          end
          add_timer_event(self_obj, game_ticks(random(2,10)), 1);
       end
    end
    
    /edit3: A bit more random but even shorter would be ...
    Code:
    procedure timed_event_p_proc begin
       if ((fixed_param == 1) and (global_var(GVAR_MAGAZINE_REPAIRED_GENERATOR) == 0)) then begin
          set_obj_visibility(self_obj, random(0,1));
          add_timer_event(self_obj, game_ticks(random(2,10)), 1);
       end
    end
    
     
    Last edited: Nov 24, 2019
  9. fffffffff

    fffffffff First time out of the vault

    19
    Mar 20, 2017
    Thank you but the idea was to have every "flick" animation's "frame" in control to create realistic one animation.