Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Crashes The Game
Mudbill Online
Muderator

Posts: 3,817
Threads: 59
Joined: Apr 2013
Reputation: 177
#11
RE: Script Crashes The Game

Just posting to mention that this exact issue has been happening to my own script lately. At a point where a script is supposed to run, the game instead freezes and I have to tab out and force close it. This only seems to happen sometimes, however. During one run, I can execute the script and it runs, then when I execute it again it might just freeze up. Sometimes it happens the first time. I don't understand what's causing it because the hpl.log does not finish printing so it shows no errors.

I think the problem I have is the same as what you have here. I think it must be somewhere within the script that causes the game to freeze, but I really don't know what is causing it. There doesn't seem to be a specific problem.

(This post was last modified: 03-13-2014, 09:27 PM by Mudbill.)
03-13-2014, 09:27 PM
Find Reply
Wapez Offline
Senior Member

Posts: 360
Threads: 37
Joined: Mar 2012
Reputation: 19
#12
RE: Script Crashes The Game

SOLVED.

The problem was indeed an infinite loop. Due to a problem with both the if-statement and the contents of it in the function Amn pointed out, it caused a loop that never ended, ultimately being too much for the engine to handle.

In my case, I solved it by implementing a new way of searching for areas that hadn't already been shooting steam. I did this like this:

PHP Code: (Select All)
void RunSteamFlow(int alEventCount){
    
int iSteamArea RandInt(16);
    
int RunCount alEventCount;
    
        if(
GetLocalVarInt("iBlockedSteamArea_"+iSteamArea) == 1){
            if(
iSteamArea && GetLocalVarInt("SteamFlowCountDirection") == 0){
                  
//SteamFlowCountDirection determines whether to add or subtract from the number that has already been used in SteamEvent();. 0 = Add, 1 = Subtract.
                
SetLocalVarInt("iSteamAreaRecount"iSteamArea 1);
                                
//Add 1 to the integer to search for an unoccupied number.
                
RunSteamFlow(RunCount);
                                
//Run the function again to keep searching for numbers until a useable one is found.
            
}
            else{
                
SetLocalVarInt("SteamFlowCountDirection"1);
                                
//Changes the SteamFlowCountDirection so the number being manipulated is being subtracted from instead.
                
SetLocalVarInt("iSteamAreaRecount"iSteamArea 1);
                                
//Subtract 1 from the integer to search for an unoccupied number.
                
RunSteamFlow(RunCount);
                                
//Run the function again to keep searching for numbers until a useable one is found.
            
}
            
            
iSteamArea GetLocalVarInt("iSteamAreaRecount");
        }
        else{
            
SteamEvent(iSteamArea);
        }
        
    
SetLocalVarInt("SteamFlowCountDirection"0);


Also, Mudbill, I'll gladly take a look at your script to see if I can help you out. I'd happily help someone so dedicated to educate this community!

Founder & Legally Accountable Publisher of Red Line Games.
Environment & Gameplay Designer and Scripter.
http://moddb.com/mods/in-lucys-eyes
(This post was last modified: 03-14-2014, 08:57 AM by Wapez.)
03-14-2014, 08:54 AM
Find Reply
Mudbill Online
Muderator

Posts: 3,817
Threads: 59
Joined: Apr 2013
Reputation: 177
#13
RE: Script Crashes The Game

That would be nice of you =)

Well, my script is rather short with big intention. It's also very specific to the entities I've made so it might be difficult for me to explain, but I'll give it a go. It's only about half way done at the moment though, but I can't finish it before I fix this issue. Prepare yourself for a long explanation! :O

I'm making a puzzle that requires the player to find small slates represeting paths. Here's an example of how a horizontal slate looks like:
Spoiler below!
[Image: expl_slate.png]
This entity also has a body with the name of "west_east" This comes in play later.
I also have slates representing vertical paths, turns and combinations. The body names of all these include the directions they face: "north_south" "south_east" "north_west_south" are examples.

These slates can be placed with sticky areas into the slots of a big frame in the floor. This frame has 5x5 slots with a few built-in slates that can't be moved. It looks like this (the empty slots have the Ankh symbol):
Spoiler below!
[Image: expl_frame.png]
This frame is also located inside a maze of sorts. The map consists of 5x5 rooms with doors in between them. The setup for this whole room is like this:
Spoiler below!
[Image: fric_sys_ex.png]
This system works in the way that each room has their own co-ordinate. The room in the middle is named x3y3. This is also the room with the cross slate as well as where the big frame is located.

The idea is to place a slate in the slot next to another used slot in order to open the door in between the represented rooms, as long as the slates connect with each other. For example placing the horizontal slate in x4y3 will open the door connecting room x3y3 and room x4y3. The naming system I'm using for the doors (they are MoveObjects btw) is "move_room1_room2. The door mentioned above is named "move_x3y3_x4y3" This is the best system I could come up with to make it organized. The first room is always the north or west room, the second room is always the south (if first is north) or east (if first is west).

The remaining things to mention within the map are just the different slates as well as the sticky areas. The slates do not use any naming system other than the body names mentioned way up, but they all include "slate" in their name. The sticky areas are named "area_co-ord" similar to the doors, except they only have 1 co-ord for the room and not the 2 connecting rooms. These areas accept entities with "slate" in their name to connect with. Upon connecting, they call the script function "AttachSlate."

Now the scripting (yay):
Spoiler below!
PHP Code: (Select All)
bool bWestbEastbNorthbSouth;

void AttachSlate(string &in asAreastring &in asBodyName)
{    
    if(
StringContains(asBodyName"west") == truebWest true; else bWest false;
    if(
StringContains(asBodyName"east") == truebEast true; else bEast false;
    if(
StringContains(asBodyName"north") == truebNorth true; else bNorth false;
    if(
StringContains(asBodyName"south") == truebSouth true; else bSouth false;
    
    for(
int x=1<= 5; ++x) for(int y=1<= 5; ++y) {
                
        
string sThisArea "area_x"+x+"y"+y;
        
string sThisDoor "move_";
            
        if(
bWest  == truesThisDoor sThisDoor +"x" + --x; else sThisDoor sThisDoor +"x" +x;
        if(
bNorth == truesThisDoor sThisDoor +"y" + --y; else sThisDoor sThisDoor +"y" +y;
        if(
bEast  == truesThisDoor sThisDoor +"_x"+ ++x; else sThisDoor sThisDoor +"_x"+x;
        if(
bSouth == truesThisDoor sThisDoor +"y" + ++y; else sThisDoor sThisDoor +"y" +y;
             
        if(
asArea == sThisArea) {
            
UpdateDoors(sThisDoor1);

            
AddDebugMessage("Area: " sThisAreafalse);
            
AddDebugMessage("Door: " sThisDoorfalse);
        }
    }
    
    
bWest false;
    
bEast false;
    
bNorth false;
    
bSouth false;
}

void UpdateDoors(string &in asDoorint alState)
{
    
AddDebugMessage("Updating Door: " asDoorfalse);
    
SetMoveObjectState(asDooralState);


So far in the script, I have not implemented the connecting slates part. So far it only opens a door leading to the room represented by the area the slate was placed in. This is where the problem occurs. Only sometimes, the game freezes up, just like what happened to you, the moment the slate connects with the area. I'm unsure why this happens. It seems to work fine with the horizontal slate in all slots (though only on the "west" side). Whenever I take a "north_east" slate, it freezes. It also freezes (randomly) if I enable the script for closing the doors again within a "DetachSlate" function, which is similar to the attach one. I have excluded it because I don't need to close the doors before I can properly open them.

Do you understand what's going on here? Any ideas? Undecided

(This post was last modified: 03-14-2014, 03:01 PM by Mudbill.)
03-14-2014, 02:59 PM
Find Reply
Wapez Offline
Senior Member

Posts: 360
Threads: 37
Joined: Mar 2012
Reputation: 19
#14
RE: Script Crashes The Game

(03-14-2014, 02:59 PM)Mudbill Wrote: Do you understand what's going on here? Any ideas? Undecided

After going through it really briefly, your script looks fine to me. However, while trying it in my head, I noticed that sometimes a co-ordinate will result in containing a zero in one of it's numbers. Like this:

Spoiler below!

PHP Code: (Select All)
bool bWestbEastbNorthbSouth;

void AttachSlate(string &in asAreastring &in asBodyName)
{    
    if(
StringContains(asBodyName"west") == truebWest true; else bWest false;
    if(
StringContains(asBodyName"east") == truebEast true; else bEast false;
    if(
StringContains(asBodyName"north") == truebNorth true; else bNorth false;
    if(
StringContains(asBodyName"south") == truebSouth true; else bSouth false;
    
    
//bWest == true
    //bEast == true
    //bNorth == false
    //bSouth == false
    
    
for(int x=1<= 5; ++x) for(int y=1<= 5; ++y) {
                
        
string sThisArea "area_x"+x+"y"+y;
        
string sThisDoor "move_";
            
        if(
bWest  == truesThisDoor sThisDoor +"x" + --x; else sThisDoor sThisDoor +"x" +x;
        
//move_x0
        
if(bNorth == truesThisDoor sThisDoor +"y" + --y; else sThisDoor sThisDoor +"y" +y;
        
//move_x0y1
        
if(bEast  == truesThisDoor sThisDoor +"_x"+ ++x; else sThisDoor sThisDoor +"_x"+x;
        
//move_x0y1_x2
        
if(bSouth == truesThisDoor sThisDoor +"y" + ++y; else sThisDoor sThisDoor +"y" +y;
        
//move_x0y1_x2y1
        
        
if(asArea == sThisArea) {
            
UpdateDoors(sThisDoor1);
            
//UpdateDoors("move_x0y1_x2y1", 1);

            
AddDebugMessage("Area: " sThisAreafalse);
            
AddDebugMessage("Door: " sThisDoorfalse);
        }
    }
    
    
bWest false;
    
bEast false;
    
bNorth false;
    
bSouth false;
}

void UpdateDoors(string &in asDoorint alState)
{
    
AddDebugMessage("Updating Door: " asDoorfalse);
    
SetMoveObjectState(asDooralState);
    
//SetMoveObjectState("move_x0y1_x2y1, 1);



This isn't what's causing your crashes, but it's a bug (unless I'm too tired and sick to be able to think straight), since I'm guessing you don't have a door named like that.

I'll keep looking for a possible cause to your problems and I'll let you know if I find something.

Founder & Legally Accountable Publisher of Red Line Games.
Environment & Gameplay Designer and Scripter.
http://moddb.com/mods/in-lucys-eyes
03-14-2014, 03:56 PM
Find Reply
Apfel Offline
Junior Member

Posts: 19
Threads: 3
Joined: Jun 2011
Reputation: 1
#15
RE: Script Crashes The Game

(03-14-2014, 02:59 PM)Mudbill Wrote: if(bWest == true) sThisDoor = sThisDoor +"x" + --x; else sThisDoor = sThisDoor +"x" +x;
if(bNorth == true) sThisDoor = sThisDoor +"y" + --y; else sThisDoor = sThisDoor +"y" +y;
if(bEast == true) sThisDoor = sThisDoor +"_x"+ ++x; else sThisDoor = sThisDoor +"_x"+x;
if(bSouth == true) sThisDoor = sThisDoor +"y" + ++y; else sThisDoor = sThisDoor +"y" +y;



Hi there,

I made some tests of your script and I noticed that there are some problems with --x and --y. Changing them to (x-1) and (y-1) solved the crashing for me. However, ++x and ++y don't seem to make any troubles.
03-14-2014, 04:35 PM
Find Reply
Wapez Offline
Senior Member

Posts: 360
Threads: 37
Joined: Mar 2012
Reputation: 19
#16
RE: Script Crashes The Game

(03-14-2014, 04:35 PM)Apfel Wrote:
(03-14-2014, 02:59 PM)Mudbill Wrote: if(bWest == true) sThisDoor = sThisDoor +"x" + --x; else sThisDoor = sThisDoor +"x" +x;
if(bNorth == true) sThisDoor = sThisDoor +"y" + --y; else sThisDoor = sThisDoor +"y" +y;
if(bEast == true) sThisDoor = sThisDoor +"_x"+ ++x; else sThisDoor = sThisDoor +"_x"+x;
if(bSouth == true) sThisDoor = sThisDoor +"y" + ++y; else sThisDoor = sThisDoor +"y" +y;



Hi there,

I made some tests of your script and I noticed that there are some problems with --x and --y. Changing them to (x-1) and (y-1) solved the crashing for me. However, ++x and ++y don't seem to make any troubles.

Yes, this is the problem I pointed out. It gives incorrect values sometimes. However this shouldn't cause the game to crash.

Founder & Legally Accountable Publisher of Red Line Games.
Environment & Gameplay Designer and Scripter.
http://moddb.com/mods/in-lucys-eyes
03-14-2014, 04:42 PM
Find Reply
Apfel Offline
Junior Member

Posts: 19
Threads: 3
Joined: Jun 2011
Reputation: 1
#17
RE: Script Crashes The Game

I did some more tests and now i know why it crashes.
It is because of an infinite loop created with the for loop

example:

for(int x=1; x<=5; x++)
{
// x=1
sThisDoor = sThisDoor +"x" + --x;
//x=0
}

Now it is x=0 and the for loop starts at the beginning with that value,
so x is raised to 1 again.
Basically x toggles between 1 and 0 and never reaches the end condition.
03-14-2014, 05:31 PM
Find Reply
Wapez Offline
Senior Member

Posts: 360
Threads: 37
Joined: Mar 2012
Reputation: 19
#18
RE: Script Crashes The Game

Nice Apfel!

Switch the for loop variables to a & b or something, and it should work.

Founder & Legally Accountable Publisher of Red Line Games.
Environment & Gameplay Designer and Scripter.
http://moddb.com/mods/in-lucys-eyes
03-14-2014, 05:36 PM
Find Reply
Mudbill Online
Muderator

Posts: 3,817
Threads: 59
Joined: Apr 2013
Reputation: 177
#19
RE: Script Crashes The Game

Ah, I see. Thank you =)
I'll get to that and see. Yeah, it knew it went to 0 at times, but in the terms of doors, that didn't seem to cause any problems so I just left it there. It just makes the script ignore the execution rather than crashing.

This x and y thing I really need to fix though. The point is of course to have them work together in the loop, but I can make an alternative variable to separate them.

Thanks again for pointing this out <3

Yeah, the issue seem to be fixed if I change it like this:
PHP Code: (Select All)
    for(int a=1<= 5; ++a) for(int b=1<= 5; ++b) {

        
int x a;
        
int y b

Now I guess I'm back to trying to finish this and make it potentially open several doors and to fix the directions Big Grin

(This post was last modified: 03-14-2014, 06:22 PM by Mudbill.)
03-14-2014, 05:49 PM
Find Reply




Users browsing this thread: 1 Guest(s)