Level controler

Topics regarding Scripting with Reality Factory
Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Level controler

Post by Veleran » Fri Jan 29, 2016 7:31 pm

I had the cage base parent model and sides children lowered to first get the proper static lightning and the controler is supposed to lift it up in wait for the player to push the button to lower the cage according the cage animation key of time 2 for example.
Of course the level preview just stays minimized with the message the levelcontroler is faulty.
i can not find one of the symbols of the message but it is about -runtime error i *@ -like.

Code: Select all

{ 
	Start[ ()
	{
            Console(true);
			SetPlatformTargetTime("Cage_96x64_1_Base", "1");
			NewOrder("Wait");
      } ] 
		    
	  
	Wait[ () 
      {            
            if(GetEventState("Cage_96x64_1_Trigger") = true)
            SetPlatformToTargetTime("Cage_96x64_1_Base", "2");
     } ] 
} 
Also,do you type a szEntity name for the platform or just the name of the model platform?

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Level controler

Post by Allanon » Fri Jan 29, 2016 11:57 pm

You are using low level methods so you need to call LowLevel() . Also you are missing braces after the if statement and keyTime is a float value:

Code: Select all

{ 
    Start[()
    {
         Console(true);
         LowLevel("Setup");
    }] 

    Setup[()
    {
         SetPlatformTargetTime("Cage_96x64_1_Base", 1.0);
         self.think = "Wait";
    }]
          
    Wait[() 
    {            
         if (GetEventState("Cage_96x64_1_Trigger") = true)
         {
              SetPlatformToTargetTime("Cage_96x64_1_Base", 2.0);
         }
    }] 
} 

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Level controler

Post by Veleran » Sat Jan 30, 2016 7:10 am

Thank you very much.However i still get the same shutdown.
Until i find what i might have missed with the moving platform settings,i might just skip the up and down movement of the cage to get on with other more basic mechanics like traps.

I will try trigger the move up key frame with a trigger during at level start and then try make it go down on next frame by adding names to the keyframes and using bRunFromList (Animation runs to next time in provided list each time triggered) and see if it the cage will move up or down each time you press the button.

If i mess it i might as well post in the designers section.

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Level controler

Post by Allanon » Sat Jan 30, 2016 9:49 am

OK, I did some testing and got it to work. The reason the script crashed is because the LevelController entity is already in low level mode when it calls the SpawnOrder. You were calling NewOrder() which is a high level method and I was calling LowLevel() when it was already in low level mode. This caused that error to show up.

Let me tell you how my level was setup:

I created a model named "test" that has 2 keys, one at 0.0 and the other at 2.0, I assigned this model to a MovingPlatform entity. I assigned the MovingPlatform entity a szEntityName of "movingplatform1".

I created another model named "trig" and assigned it to a Trigger entity. I assigned the Trigger entity a szEntityName of "trigger1".

I created a LevelController entity and added the script name and set SpawnOrder to "Start"

Here is the script that worked for me:

Code: Select all

{ 
    Start[()
    {
         Console(true);
         SetPlatformTargetTime("movingplatform1", 1.0);
         self.think = "Wait";
    }] 

              
    Wait[() 
    {            
         if (GetEventState("trigger1") = true)
         {
             SetPlatformToTargetTime("movingplatform1", 2.0);
         }
    }] 
} 


Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Level controler

Post by Veleran » Sat Jan 30, 2016 10:23 am

Thank you very much.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Level controler

Post by Veleran » Sat Jan 30, 2016 1:18 pm

I was thinking even making the cage go back to frame time 2 which is up when you press the trigger model button for a second time and tried copying the last lines and as i expected it did not work.
Should i add a new order for a simple button reset or something?Am not sure how to do this in low level.
For the moment i leave it as it is since it works fine.

Code: Select all

{ 
    Start[()
    {
         Console(true);
         SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);
         self.think = "Wait";
    }] 
 
              
    Wait[() 
    {            
         if (GetEventState("Cage_96x64_1_Trigger") = true)
         {
            SetPlatformTargetTime("Cage_96x64_1_Base", 0.0);				 
         }
    }] 
} 

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Level controler

Post by Allanon » Sat Jan 30, 2016 4:13 pm

Maybe something like this:

Code: Select all

{ 
    Start[()
    {
         Console(true);
         SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);
         self.think = "Wait";
    }] 
 
              
    Wait[() 
    {            
         if (GetEventState("Cage_96x64_1_Trigger") = true)
         {
             CurrentTime = GetPlatformCurrentTime("Cage_96x64_1_Base");

             if (CurrentTime = 2.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 0.0);
             }
             
             if (CurrentTime = 0.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);
             }           
         }
    }] 
}

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Level controler

Post by Veleran » Sat Jan 30, 2016 5:25 pm

Now the cage is truly luxurious.Now all is left is to be able to shoot a second optional trigger from within the cage in case you want to get lifted and reach something higher.
How i add that "else " "or" option in the script for a second trigger (shoot only trigger model) to function,i wonder.I hope i have nt taken up your precious time with this cage thing.
Thank you again.

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Level controler

Post by Allanon » Sat Jan 30, 2016 10:08 pm

This script allows you to shoot the other trigger and have the cage go to the next keyTime and then you can press the original trigger to go back down. Just replace "OtherTrigger" with the szEntityName of the other trigger, and 3.0 with the correct keyTime:

Code: Select all

{ 
    Start[()
    {
         Console(true);
         SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);
         self.think = "Wait";
    }] 
 
              
    Wait[() 
    {            
         if (GetEventState("Cage_96x64_1_Trigger") = true)
         {
             CurrentTime = GetPlatformCurrentTime("Cage_96x64_1_Base");

             if (CurrentTime = 2.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 0.0);
             }
             
             if (CurrentTime = 0.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);
             }       

             if (CurrentTime = 3.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);
             }               
         }
                  
         if (GetEventState("OtherTrigger") = true)
         {
             CurrentTime = GetPlatformCurrentTime("Cage_96x64_1_Base");

             if (CurrentTime = 2.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 3.0);
             }
         }           

    }] 
}
Also, I don't mind writing scripts, if you need others just post here and I'll do my best to help.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Level controler

Post by Veleran » Sun Jan 31, 2016 6:49 am

I am grateful,thank you.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Level controler

Post by Veleran » Thu Feb 04, 2016 1:52 pm

I still have to get it to work.Do i need to add a frame at time 3?
Is i t supposed to go to the next frame as you mentioned ,the time 3?

So far i had only frame from 0.0 (down) to 2.0 (up) .

My first idea was to add events at the frames to use the two triggers,one for each frame but i failed there.
The manual does not show an example of platform entity settings that is controller by a list of events,and i will possibly ask in the level design about that because i would like to know anyway how to use the list of events, i must be useful.

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Level controler

Post by Veleran » Thu Feb 04, 2016 5:03 pm

I made it work,by changing the frame times.Thanks again.I still do not know if i need that if it is at frame 3 since i do not have frames up to that time.Should i remove those lines?

Code: Select all

              if (CurrentTime = 3.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);

Code: Select all

{ 
    Start[()
    {
         Console(false);
         SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);
         self.think = "Wait";
    }] 
 
              
    Wait[() 
    {            
         if (GetEventState("Room_1_Button_1_Trigger") = true)
         {
             CurrentTime = GetPlatformCurrentTime("Cage_96x64_1_Base");

             if (CurrentTime = 2.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 0.0);
             }
             
             if (CurrentTime = 0.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);
             }       

             if (CurrentTime = 3.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);
             }               
         }
                  
         if (GetEventState("Room_1_Button_2_Trigger") = true)
         {
             CurrentTime = GetPlatformCurrentTime("Cage_96x64_1_Base");

             if (CurrentTime = 0.0)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", 2.0);
             }
         }           

    }] 
}

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Level controler

Post by Allanon » Fri Feb 05, 2016 12:05 am

I assumed your model went from 0.0 to 2.0 for the 1st floor and 2nd floor. I was thinking you would add another keyframe to the model's animation to go to the 3rd floor and that would be 3.0. If that is not correct then set the keyTimes to whatever keyTime corresponds to the floors you want. Also if my logic is incorrect then please explain exactly what you want and I will create a script that does it.

To make it easy I rewrote the script with variables for each floor and added comments:

Code: Select all

{ 
    Floor_1    [0.0]    // keyTime for 1st floor
    Floor_2    [2.0]    // keyTime for 2nd floor
    Floor_3    [3.0]    // keyTime for 3rd floor

    Start[()
    {
         Console(false);
         //Move platform to 2nd floor
         SetPlatformTargetTime("Cage_96x64_1_Base", Floor_2);
         self.think = "Wait";
    }] 
 
              
    Wait[() 
    {            
         if (GetEventState("Room_1_Button_1_Trigger") = true)
         {
             CurrentTime = GetPlatformCurrentTime("Cage_96x64_1_Base");
             
             // if platform is on 2nd floor move to 1st floor
             if (CurrentTime = Floor_2)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", Floor_1);
             }
             
             // if platform is on 1st floor move to 2nd floor
             if (CurrentTime = Floor_1)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", Floor_2);
             }       
             
             // if platform is on 3rd floor move to 2nd floor
             if (CurrentTime = Floor_3)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", Floor_2);
             }               
         }
                  
         if (GetEventState("Room_1_Button_2_Trigger") = true)
         {
             CurrentTime = GetPlatformCurrentTime("Cage_96x64_1_Base");

             // if platform is on 2nd floor then move to 3rd floor
             if (CurrentTime = Floor_2)
             {
                 SetPlatformTargetTime("Cage_96x64_1_Base", Floor_3);
             }
         }           

    }] 
}

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Level controler

Post by Veleran » Fri Feb 05, 2016 9:07 pm

The previous version suits fine.I think some comments could be added to show that the cage is in room 1.
There is room 1 with three buttons so far.
You hit button 1 and cage goes down.Get in the cage,shoot button 2.
The cage goes up about 128 units,and then you can shoot button 3 and trigger the door of room 1 to exit to the next corridor.
Something like that for now.

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: Level controler

Post by Allanon » Fri Feb 05, 2016 10:12 pm

Here is the new script, I added a lot more variables with names that reflect that they are for room 1, this will make it easier to add other rooms to this controller. You will need to add the door szEntityName and keyTime. Plus change the keyTime for the third floor which is the corridor.

Code: Select all

{ 
    // Room 1's variables
    Room_1_Floor_1    [0.0]    // keyTime for 1st floor
    Room_1_Floor_2    [2.0]    // keyTime for 2nd floor
    Room_1_Floor_3    [1.0]    // keyTime for 3rd floor which is the corridor

    Room_1_Cage_Door_keyTime  [2.0]        // keyTime for cage door open animation
    Room_1_Cage_Door          [Cage_Door]  // szEntityName for cage door 
    
    Room_1_Trigger_1  [Room_1_Button_1_Trigger]   // trigger that causes the cage to go to 1st floor
    Room_1_Trigger_2  [Room_1_Button_2_Trigger]   // trigger that causes the cage to go to 3rd floor
    Room_1_Trigger_3  [Room_1_Button_3_Trigger]   // trigger that opens cage door

    Room_1_Cage   [Cage_96x64_1_Base] // szEntityName of cage platform
    

    Start[()
    {
         Console(true);
         //Move Room 1's cage to 2nd floor
         SetPlatformTargetTime(Room_1_Cage, Floor_2);
         self.think = "Room_1";
    }] 
 

    // Controllers for Room 1    
    Room_1[() 
    {    
         // If button 1 is pressed and cage is on 2nd floor
         // then move cage to 1st floor        
         if (GetEventState(Room_1_Trigger_1) = true)
         {
             CurrentTime = GetPlatformCurrentTime(Room_1_Cage);
             
             if (CurrentTime = Room_1_Floor_2)
             {
                 SetPlatformTargetTime(Room_1_Cage, Room_1_Floor_1);
             }
         }
             

         // If button 2 is shot and cage is on 1st floor
         // then move cage to 3rd floor        
         if (GetEventState(Room_1_Trigger_2) = true)
         {
             CurrentTime = GetPlatformCurrentTime(Room_1_Cage);
             
             if (CurrentTime = Room_1_Floor_1)
             {
                 SetPlatformTargetTime(Room_1_Cage, Room_1_Floor_3);
             }
         }


         // If button 3 is shot and cage is on 3rd floor
         // then open door        
         if (GetEventState(Room_1_Trigger_3) = true)
         {
             CurrentTime = GetPlatformCurrentTime(Room_1_Cage);
             
             if (CurrentTime = Room_1_Floor_3)
             {
                 SetDoorTargetTime(Room_1_Cage_Door, Room_1_Cage_Door_keyTime); 
             }
         }

    }] 
}

Post Reply