Skip to content
View in the app

A better way to browse. Learn more.

Learn more

Parking Script Bug

Hello everyone. I'm currently working on a "small" update to my Northview mod among other things I created a precision parking script. First I want to give a huge shout out to Itchboy for helping me with a few road blocks and for some helpful tips. The script works great in my "Testing" mod which is essentially base game + a handful of my created scripts / content. When I transferred and implemented the script over to my Northview Mod (which is a glorified LA Submod), it works just fine...minus this one bug that I can't seem to find the cause for.

Here is the script in action in my testing mod:

 

 

Here is a video of the bug: (Ignore the audio...my co-author and I were in discord working on different tasks when this was hastily and angrily recorded by myself).

As you can see the vehicles rotate on their side when the parking marker is set a long distance away. If I keep the marker close to the vehicle, there is no bug. Itchy and myself are at a loss...so I'm punting it out to all of you for ideas on what to check or for ideas as to what the cause is. It's very odd because this doesn't seem to be a problem in my "Testing" Mod and only in my full mod. If I can't figure this out my workaround will be to limit the distance from the vehicle that the parking marker can be placed....but this is far from ideal.

For sure its the rotation of the vehicle that's causing this. 

Here is the code for the actual parking of the vehicle:

object PrecisionPark_initiate : CommandScript
{
    PrecisionPark_initiate()
    {
         SetIcon("initiate");
    }
 
    bool CheckPossible(GameObject *Caller)
    { return true; }
 
    bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
    { return true; }
 
    void PushActions(GameObject *Caller, Actor *Target, int childID)
    {
 
        if( childID == 1 ) //Rotate to park
        {
            float r[9];
            GameObject obj( Target );
            obj.GetRotation( r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8] );
            Caller->SetRotation( r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8] );
            //Caller->SetRotation( &obj ); //Meh...old way of doing it. Itchboy suggested the other setrotation method
            Caller->PushActionExecuteCommand( ACTION_NEWLIST, "PrecisionPark_initiate", Target, 2, false ); //Cleanup
        }
        else if( childID == 2 ) //Cleanup parking marker
        {
            GameObject obj( Target );
            obj.PushActionDeleteOwner( ACTION_NEWLIST );
        }
        else //Parking Logic start
        {
            Vehicle v( &Game::GetActor( Caller->GetUserData() ) ); //Our original vehicle we want to park
 
            //Lock Parking marker - Disable modification but allow canceling
            Caller->RemoveCommand("PrecisionPark_leftward");
            Caller->RemoveCommand("PrecisionPark_forward");
            Caller->RemoveCommand("PrecisionPark_initiate");
            Caller->RemoveCommand("PrecisionPark_backward");
            Caller->RemoveCommand("PrecisionPark_rightward");
            Caller->RemoveCommand("PrecisionPark_move");
            Caller->RemoveCommand("PrecisionPark_rotClock");
            Caller->RemoveCommand("PrecisionPark_rotCounterClock");
 
 
            //Reselect our vehicle
            Caller->Deselect();
            v.Select();
 
            //Visually show initialization
            Caller->ChangePrototype( PARKING_MARKER_WAIT );
 
            //Set Death Timer...truthfully this is a fallback incase traveling gets interrupted. It causes the marker to delete iteself after a small delay.
             Caller->PushActionWait( ACTION_NEWLIST, 5.0f );
             Caller->PushActionDeleteOwner( ACTION_APPEND );
 
            //Initiate Move
            v.PushActionMove( ACTION_NEWLIST, Caller->GetPosition() );
            v.PushActionExecuteCommand( ACTION_APPEND, "PrecisionPark_initiate", Caller, 1, false ); //Set Rotation
            v.PushActionExecuteCommand( ACTION_APPEND, "PrecisionPark_initiate", Caller, 2, false ); //Cleanup
        }
    }
};

 

My best guess is that it has nothing to do with the code, since it works in the test mod...but has something to do with the models/prototypes of the vehicles, since both of the ones in the example are custom vehicles.

I appreciate any and all feedback. Thanks! http://www.emergency-planet.com/uploads/emoticons/default_grinsevil.gif 

Featured Replies

  • Author

So I have good news. After HOURS upon HOURS of debugging, I solved my issue. Here's my final report:

 

The bugs caused by this script were multifactorial in nature. In the code above, I took an Actor variable, which holds the data for a Vehicle, and assigned it to a GameObject. The GameObject must handle rotation data differently than vehicles or must be structures differently, because that was the true source of the bug. After changing 

GameObject obj( Target );

to

Vehicle v( Target );

the issue of the weird rotation was solved. Unfortunately, fixing this issue was only the beginning. A whole host of bugs began to appear, some of which caused the game to crash after some time. After multiple fixes, it became apparent to me that a lot of my headaches were caused because the parking marker was getting deleted too early in some cases.

I noticed that a lot of bugs happened when I sent vehicles to park long distances away. Well, in my script, when a player initiates parking, the marker remains for 5 seconds, then deletes itself. Why would I do that? Well, that was my solution to handling orphaned markers. My thought was, if a player sent their vehicle to park, and then interrupted it, then the marker would remain until the player decided to park again. To me this would have been unsightly....and I can do much better than that. So I set the markers to "auto-prune" after a 5 second delay. The delay allowed the player to see the spot their vehicle was going to park at while the vehicle was moving there. At "close" distances, the vehicle would reach the marker before it pruned and everything would be fine. If it took the vehicles longer than 5 (seconds), as was the case for "long distance" moves, then the marker would delete itself before the vehicle reached it. Once the vehicle reached the spot where the marker was, it would try and get rotation data from a non-existent object and bug the prototype of the vehicle (causing it to lose doors and maybe even flip). Originally, it was my thought that the PushActionExecute commands passed a COPY of the marker's vehicle data, but it soon dawned on me that they were passing pointers to the original vehicle data. Unfortunately for me, that meant that when it came time to pull the marker's data to find its rotation, the data no longer existed. To solve this, what I did was immediately Hide() the marker when parking was initiated, so that the marker was no longer visible (which solved the issue of unsightly stray markers). I learned that using Hide() on the marker caused the same behavior as before and was not the answer (it acted as though I had deleted the marker). In the end, I ended up removing the visibility of the marker by replacing it's prototype with a "dummy" one which was linked to a tiny 3D box that is located well below the map floor (in other words it was invisible). This was the answer I needed. The marker would be invisible and would remain "alive" until either the vehicle finished parking or until the player decided to park again (since the script first deletes any existing markers before creating a new one). I figured at worst, the highest number of markers on the map at one time could only be equal to the number of vehicles on the map (assuming each one has a stray marker out), and in my opinion that isn't bad, especially since each vehicle can only have one marker out at a time.

 

After all that, I had the rotation bug fixed, but the script still wasn't stable. There were many odd behaviors still occurring. After some investigation I narrowed it down to direct use of pointer variables, and my overuse of Inline calls.
I used Caller and Target a lot in my code (ie. Caller>SomeFunction() ), and I guess calling directly on the pointer was more volatile than copying the data to a new Vehicle object. 
Overusing inline calls was pretty sloppy on my part. I thought it saved lines of codes when I first wrote them, but they caused me headaches later. At one point in the code, I was checking if one or more parking markers already existed for the particular vehicle that is calling the command like:

if( Game::GetGameObjects(markerOwner).GetNumObjects() > 0 ) //Delete any pre-existing parking markers for this vehicle...if any.
{
	for( int i = 0; i < Game::GetGameObjects(markerOwner).GetNumObjects(); i++ )
		Game::GetGameObjects( markerOwner ).GetObject(i)->PushActionDeleteOwner(ACTION_NEWLIST);
}

Calling "Game::GetGameObjects(markerOwner).GetNumObjects()" twice in a row and "Game::GetGameObjects( markerOwner ).GetObject(i)->PushActionDeleteOwner(ACTION_NEWLIST)" at the end proved to be very problematic, especially when data changed between the three calls. This was the source of the CTD I was experiencing. Data would change between the two GetNumObjects() (most likely from 1 to 0). So when GetObject(i) was GetObject(0), it would return an ArrayIndexOutOfBounds error, causing an instant CTD. The solution? Copy the damn data into an objectlist the first time I call Game::GetGameObjects() like: "GameObjectList list( Game::GetGameObjects( markerOwner ) ); list.GetNumbObjects();"

 

After all that, the script began to work. As of right now it's stable and working like a charm. *crosses fingers*

 

Sorry for the long winded response. Maybe this will be helpful to others (probably not). http://www.emergency-planet.com/uploads/emoticons/default_smile.png

 

Call me primitive but Id have the marker be deleted only upon the vehicle arriving at the position. 

In the moveToMarker command, Id set it like this:

Vehicle v(Caller); and GameObject marker(Target);

childID 0 makes the vehicle move to the marker. Then the command will be called again but as childID 1

childID 1 makes the vehicle rotate to the position of the marker. This childID then calls the command again as childID 2 this time.

childID 2 deletes the marker once everything is done with it.

If the vehicle gets interrupted on the way there, then Id just assign a command to delete the marker that is assigned to the marker itself.

In general, the complexity of the parking script is why I avoided it entirely and just made a rotate command.


I think its well done how you put the functions within the conditions. They're things I dont use enough. Sadly, some of those conditions, when repeated over again end up being longer than just declaring a variable for them. The thing I focus on when it comes to optimization is the character count on the bottom. That seems to matter more than the # of lines in the script.

Guest
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.