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
Puzzle Script Bug
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#1
Puzzle Script Bug

Hai. I need some help figuring out a strange bug in my script. This is quite advanced, at least for me, so be prepared xP

I already explained the situation in another thread so I'll just throw some of that in here.

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."

This is the complete script I've developed so far. It's near completion and I'm very proud of it. x)
I added some comments to help explain what happens. Hopefully you advanced scripters understand it all. If you have any questions, I'll try to explain it further. ^^

You might wanna copy it into an editor to read it more easily.
Spoiler below!
PHP Code: (Select All)
bool GetBoolLocalVarInt(string &in asVarName//Just a simple function for changing the integers below into booleans. I prefer true/false over 1/0.
{
    if(
GetLocalVarInt(asVarName) == 0) return false;
    else return 
true;
}

void OnStart()
{
    
/* All possible doors. */
    
for(int a=1<= 5; ++a) for(int b=1<= 5; ++b) {//Loops 25 times, creating a total of 100 variables. 0 = false, which means door is closed.
        
SetLocalVarInt("x"+a+"y"+b+"_w"0);
        
SetLocalVarInt("x"+a+"y"+b+"_n"0);
        
SetLocalVarInt("x"+a+"y"+b+"_e"0);
        
SetLocalVarInt("x"+a+"y"+b+"_s"0);
    }
    
    
/* Pre-defined doors. */
    
SetLocalVarInt("x3y3_w"1);//Manually set 5 of the premade 100 into their "true" state. This allows these 5 doors to open if below statement accpets it.
    
SetLocalVarInt("x3y3_n"1);
    
SetLocalVarInt("x3y3_e"1);
    
SetLocalVarInt("x5y1_s"1);
    
SetLocalVarInt("x2y4_s"1);
}

void AttachSlate(string &in asAreastring &in asBodyName)
{            
    for(
int a=1<= 5; ++a) for(int b=1<= 5; ++b) {//Another 5x5 loop, running a maximum total of 25 times.
        
        /* Avoid conflict with loop. */
        
int x a;
        
int y b;
        
        
/* Pause at current area and ready appropriate doors for opening. */
        
string sThisArea "x"+a+"y"+b;//This creates a string for each loop which equals 25 total strings.
        
        
if(asArea == sThisArea) {//If the above string is the same as the area the slate was placed in, pause the loop until the block is finished. This is basically just checking for what the current area is.
            
            
AddDebugMessage("asArea: " asAreafalse);
            
            if(
StringContains(asBodyName"west") == true) {//The slates' bodies include the names of the directions they display. This checks for which directions are going to be enabled.
                
SetLocalVarString("WestDoor"sThisArea "_w");//This creates a dynamic string which is used as the name of 1 of the 100 variables up top.
                
SetLocalVarInt(GetLocalVarString("WestDoor"), 1);//This sets a door to its "true" state. This variable was already created up top. It inputs the string above.
                
AddDebugMessage("West Variable: > " GetLocalVarString("WestDoor") + " < is now: " GetLocalVarInt(GetLocalVarString("WestDoor")), false);
            }
            if(
StringContains(asBodyName"north") == true) {//Same thing as with the "west" situation, just with "north", "east" and "south".
                
SetLocalVarString("NorthDoor"sThisArea "_n");
                
SetLocalVarInt(GetLocalVarString("NorthDoor"), 1);
                
AddDebugMessage("North Variable: > " GetLocalVarString("NorthDoor") + " < is now: " GetLocalVarInt(GetLocalVarString("NorthDoor")), false);
            }
            if(
StringContains(asBodyName"east") == true) {
                
SetLocalVarString("EastDoor"sThisArea "_e");
                
SetLocalVarInt(GetLocalVarString("EastDoor"), 1);
                
AddDebugMessage("East Variable: > " GetLocalVarString("EastDoor") + " < is now: " GetLocalVarInt(GetLocalVarString("EastDoor")), false);
            }
            if(
StringContains(asBodyName"south") == true) {
                
SetLocalVarString("SouthDoor"sThisArea "_s");
                
SetLocalVarInt(GetLocalVarString("SouthDoor"), 1);
                
AddDebugMessage("South Variable: > " GetLocalVarString("SouthDoor") + " < is now: " GetLocalVarInt(GetLocalVarString("SouthDoor")), false);
            }
            
            
/* Check for which doors are already available to open. Also fix the modified value. */
            
SetLocalVarString("WestReady""x" + --"y" y); ++x;//This creates dynamic strings used to check if the room the door is leading to has accepted the direction that matches the current room's door. Basically if you're going west, the room to the west needs to have its east variabled set to 1 (true).
            
SetLocalVarString("NorthReady""x" "y" + --y); ++y;//The ++x; and similar are used to reset the value changed, so it doesn't affect the next time it's used.
            
SetLocalVarString("EastReady""x" + ++"y" y); --x;
            
SetLocalVarString("SouthReady""x" "y" + ++y); --y;
            
            
string sThisRoom "x"+x+"y"+y;//This creates another dynamic string similar to the sThisArea above. 

            
AddDebugMessage("WestReady: " GetLocalVarString("WestReady") + "_e = " GetLocalVarInt(GetLocalVarString("WestReady")), false);
            
AddDebugMessage("NorthReady: " GetLocalVarString("NorthReady") + "_s = " GetLocalVarInt(GetLocalVarString("NorthReady")), false);
            
AddDebugMessage("EastReady: " GetLocalVarString("EastReady") + "_w = " GetLocalVarInt(GetLocalVarString("EastReady")), false);
            
AddDebugMessage("SouthReady: " GetLocalVarString("SouthReady") + "_n = " GetLocalVarInt(GetLocalVarString("SouthReady")), false);

            
/* If everything is set, open the appropriate door(s). */
            
if(GetBoolLocalVarInt(GetLocalVarString("WestReady")+"_e") == true && GetBoolLocalVarInt(GetLocalVarString("WestDoor")) == true)//This checks if both directions of the relative rooms have their values set to 1 (true). Since all rooms are named room1_room2 in co-ords, if you're going up the scale, room1 needs to be - x in relation to room2 (which is current). 
                
if(GetEntityExists("move_" GetLocalVarString("WestReady") + "_" sThisRoom) == true//This just checks if the door exists before opening it.
                    
UpdateDoors("move_" GetLocalVarString("WestReady") + "_" sThisRoom1);//This calls the function that opens the door. The door is named move_room1_room2 so because this goes west, room1 needs to be - x in relation, therefore WestReady is called before sThisRoom (which is current).
            
            
if(GetBoolLocalVarInt(GetLocalVarString("NorthReady")+"_s") == true && GetBoolLocalVarInt(GetLocalVarString("NorthDoor")) == true)//Same thing with the 3 other directions.
                
if(GetEntityExists("move_" GetLocalVarString("NorthReady") + "_" sThisRoom) == true)
                    
UpdateDoors("move_" GetLocalVarString("NorthReady") + "_" sThisRoom1);
            
            if(
GetBoolLocalVarInt(GetLocalVarString("EastReady")+"_w") == true && GetBoolLocalVarInt(GetLocalVarString("EastDoor")) == true)
                if(
GetEntityExists("move_" sThisRoom "_" GetLocalVarString("EastReady")) == true)
                    
UpdateDoors("move_" sThisRoom "_" GetLocalVarString("EastReady"), 1);
            
            if(
GetBoolLocalVarInt(GetLocalVarString("SouthReady")+"_n") == true && GetBoolLocalVarInt(GetLocalVarString("SouthDoor")) == true)
                if(
GetEntityExists("move_" sThisRoom "_" GetLocalVarString("SouthReady")) == true)
                    
UpdateDoors("move_" sThisRoom "_" GetLocalVarString("SouthReady"), 1);
        }
    }
}

void UpdateDoors(string &in asDoorint alState)//This simply opens the MoveObject door. asDoor is set to the door name and alState is specified in the UpdateDoors script above.
{
    
AddDebugMessage("Updating Door: " asDoorfalse);
    
SetMoveObjectState(asDooralState);
}

void DetachSlate(string &in asAreastring &in asBodyName)//This detaching script is pratically the same as the attaching one, except it instead sets all values to 0 (false) and UpdateDoors uses value 0 to close the doors.
{    
    for(
int a=1<= 5; ++a) for(int b=1<= 5; ++b) {
        
        
int x a;
        
int y b;
        
        
string sThisArea "x"+a+"y"+b;
        
        if(
asArea == sThisArea) {
            
            
//AddDebugMessage("asArea: " + asArea, false);
            
            
if(StringContains(asBodyName"west") == true) {
                
SetLocalVarString("WestDoor"sThisArea "_w");
                
SetLocalVarInt(GetLocalVarString("WestDoor"), 0);
                
//AddDebugMessage("West Variable: > " + GetLocalVarString("WestDoor") + " < is now: " + GetLocalVarInt(GetLocalVarString("WestDoor")), false);
            
}
            if(
StringContains(asBodyName"north") == true) {
                
SetLocalVarString("NorthDoor"sThisArea "_n");
                
SetLocalVarInt(GetLocalVarString("NorthDoor"), 0);
                
//AddDebugMessage("North Variable: > " + GetLocalVarString("NorthDoor") + " < is now: " + GetLocalVarInt(GetLocalVarString("NorthDoor")), false);
            
}
            if(
StringContains(asBodyName"east") == true) {
                
SetLocalVarString("EastDoor"sThisArea "_e");
                
SetLocalVarInt(GetLocalVarString("EastDoor"), 0);
                
//AddDebugMessage("East Variable: > " + GetLocalVarString("EastDoor") + " < is now: " + GetLocalVarInt(GetLocalVarString("EastDoor")), false);
            
}
            if(
StringContains(asBodyName"south") == true) {
                
SetLocalVarString("SouthDoor"sThisArea "_s");
                
SetLocalVarInt(GetLocalVarString("SouthDoor"), 0);
                
//AddDebugMessage("South Variable: > " + GetLocalVarString("SouthDoor") + " < is now: " + GetLocalVarInt(GetLocalVarString("SouthDoor")), false);
            
}
            
            
SetLocalVarString("WestReady""x" + --"y" y); ++x;
            
SetLocalVarString("NorthReady""x" "y" + --y); ++y;
            
SetLocalVarString("EastReady""x" + ++"y" y); --x;
            
SetLocalVarString("SouthReady""x" "y" + ++y); --y;
            
            
string sThisRoom "x"+x+"y"+y;

            if(
GetEntityExists("move_" GetLocalVarString("WestReady") + "_" sThisRoom) == true)//This lacks the check for whether each direction is set to true because there's no need to check for it, because the doors will be closed if either is 0 (false).
                
UpdateDoors("move_" GetLocalVarString("WestReady") + "_" sThisRoom0);
        
            if(
GetEntityExists("move_" GetLocalVarString("NorthReady") + "_" sThisRoom) == true)
                
UpdateDoors("move_" GetLocalVarString("NorthReady") + "_" sThisRoom0);
            
            if(
GetEntityExists("move_" sThisRoom "_" GetLocalVarString("EastReady")) == true)
                
UpdateDoors("move_" sThisRoom "_" GetLocalVarString("EastReady"), 0);
            
            if(
GetEntityExists("move_" sThisRoom "_" GetLocalVarString("SouthReady")) == true)
                
UpdateDoors("move_" sThisRoom "_" GetLocalVarString("SouthReady"), 0);
        }
    }



Okay now to the problem. Sometimes an incorrect door opens. It's a strange situation and I'm unsure why it happens, but in certain situations with 2x2 slates placed next to each other, a door between them opens even if it shouldn't. Here, look at this:
Spoiler below!
[Image: expl_issue.png]

As you can see, rooms x2y2 and x2y3 do not connect, therefore the door (named "move_x2y2_x2y3") should not open. If you place the turn in x2y3 last, it doesn't. If you place the horizontal slate in x2y2 last, it opens. I'm really not sure why, because according to the script, both the 2 rooms involved with the door need to have their variable set to 1. The debug message even tells me the variable is set to 0. Do you guys have any ideas as to why this happens?

If you want, I might be able to send you the whole contraption. Just PM me though, I'd rather not have it spread too much yet. ^^

03-23-2014, 02:40 AM
Find
Apfel Offline
Junior Member

Posts: 19
Threads: 3
Joined: Jun 2011
Reputation: 1
#2
RE: Puzzle Script Bug

Spoiler below!
PHP Code: (Select All)
void AttachSlate(string &in asAreastring &in asBodyName)
{       
    for(
int a=1<= 5; ++a) for(int b=1<= 5; ++b) {
     
        
int x a;
        
int y b;
        
        
string sThisArea "x"+a+"y"+b;
        
        if(
asArea == sThisArea) {
            
            
AddDebugMessage("asArea: " asAreafalse);
            
            if(
StringContains(asBodyName"west")) {
                
SetLocalVarString("WestDoor"sThisArea "_w");
                
SetLocalVarInt(GetLocalVarString("WestDoor"), 1);
                
AddDebugMessage("West Variable: > " GetLocalVarString("WestDoor") + " < is now: " GetLocalVarInt(GetLocalVarString("WestDoor")), false);
            }
            if(
StringContains(asBodyName"north")) {                // x=2, y=3   (first slate: put turn in x2y3)
                
SetLocalVarString("NorthDoor"sThisArea "_n");    // NorthDoor = "x2y3_n"
                
SetLocalVarInt(GetLocalVarString("NorthDoor"), 1);    // x2y3_n = 1
                
AddDebugMessage("North Variable: > " GetLocalVarString("NorthDoor") + " < is now: " GetLocalVarInt(GetLocalVarString("NorthDoor")), false);
            }
            if(
StringContains(asBodyName"east")) {                // x=2, y=3
                
SetLocalVarString("EastDoor"sThisArea "_e");    // EastDoor = "x2y3_e"
                
SetLocalVarInt(GetLocalVarString("EastDoor"), 1);    // x2y3_e = 1
                
AddDebugMessage("East Variable: > " GetLocalVarString("EastDoor") + " < is now: " GetLocalVarInt(GetLocalVarString("EastDoor")), false);
            }
            if(
StringContains(asBodyName"south")) {
                
SetLocalVarString("SouthDoor"sThisArea "_s");
                
SetLocalVarInt(GetLocalVarString("SouthDoor"), 1);
                
AddDebugMessage("South Variable: > " GetLocalVarString("SouthDoor") + " < is now: " GetLocalVarInt(GetLocalVarString("SouthDoor")), false);
            }
                                                                          
// x=2, y=2    (second slate: put horiz. in x2y2)
            
SetLocalVarString("WestReady""x" + --"y" y); ++x;    // WestReady     = "x1y2"
            
SetLocalVarString("NorthReady""x" "y" + --y); ++y;    // NorthReady     = "x2y1"
            
SetLocalVarString("EastReady""x" + ++"y" y); --x;    // EastReady    = "x3y2"
            
SetLocalVarString("SouthReady""x" "y" + ++y); --y;    // SouthReady    = "x2y3"
            
            
string sThisRoom "x"+x+"y"+y;                                // sThisRoom    = "x2y2"

            
AddDebugMessage("WestReady: " GetLocalVarString("WestReady") + "_e = " GetLocalVarInt(GetLocalVarString("WestReady")), false);
            
AddDebugMessage("NorthReady: " GetLocalVarString("NorthReady") + "_s = " GetLocalVarInt(GetLocalVarString("NorthReady")), false);
            
AddDebugMessage("EastReady: " GetLocalVarString("EastReady") + "_w = " GetLocalVarInt(GetLocalVarString("EastReady")), false);
            
AddDebugMessage("SouthReady: " GetLocalVarString("SouthReady") + "_n = " GetLocalVarInt(GetLocalVarString("SouthReady")), false);


            if(
GetBoolLocalVarInt(GetLocalVarString("WestReady")+"_e") && GetBoolLocalVarInt(GetLocalVarString("WestDoor")))
                if(
GetEntityExists("move_" GetLocalVarString("WestReady") + "_" sThisRoom) == true)
                    
UpdateDoors("move_" GetLocalVarString("WestReady") + "_" sThisRoom1);
            
            if(
GetBoolLocalVarInt(GetLocalVarString("NorthReady")+"_s") && GetBoolLocalVarInt(GetLocalVarString("NorthDoor")))
                if(
GetEntityExists("move_" GetLocalVarString("NorthReady") + "_" sThisRoom) == true)
                    
UpdateDoors("move_" GetLocalVarString("NorthReady") + "_" sThisRoom1);
            
            if(
GetBoolLocalVarInt(GetLocalVarString("EastReady")+"_w") && GetBoolLocalVarInt(GetLocalVarString("EastDoor")))
                if(
GetEntityExists("move_" sThisRoom "_" GetLocalVarString("EastReady")) == true)
                    
UpdateDoors("move_" sThisRoom "_" GetLocalVarString("EastReady"), 1);
            
            if(
GetBoolLocalVarInt(GetLocalVarString("SouthReady")+"_n") && GetBoolLocalVarInt(GetLocalVarString("SouthDoor")))   // x2y3_n = true && SouthDoor = ?
                
if(GetEntityExists("move_" sThisRoom "_" GetLocalVarString("SouthReady")) == true)
                    
UpdateDoors("move_" sThisRoom "_" GetLocalVarString("SouthReady"), 1);                               // move_x2y2_x2y3
        
}
    }




So, I looked at your script regarding your example that the door opens when it's not supposed to. And I can just guess what the problem might be.
So here are my thoughts:

First you place the turn (slate north east) in room x2y3. That sets the VarInt x2y3_n = 1.
Second you place the horizontal (slate west east) in room x2y2. That sets VarString SouthReady = "x2y3".

So in this part of the Script
Spoiler below!
PHP Code: (Select All)
if(GetBoolLocalVarInt(GetLocalVarString("SouthReady")+"_n") && GetBoolLocalVarInt(GetLocalVarString("SouthDoor")))   // x2y3_n = true && SouthDoor = ? 

returns the first part of the if statement a true. So the issue might be in the second part.

As I can see in your picture that there are slates placed which, I guess, contains the string "south", so I think that something is stored in LocalVarString("SouthDoor").

It might help resetting these Vars (example:SetLocalVarString("SouthDoor", ""))
right after: if(asArea == sThisArea) {




Well, that is all I can think of. I don't know if that helps or if that's the issue anyway.
03-23-2014, 06:16 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#3
RE: Puzzle Script Bug

Sorry for late answer xP

I really didn't expect to explain this well enough for someone to understand and even come with a possible solution. As simple as it was, resetting the strings indeed seemed to fix the problem. Thank you so much <3

I've been working on this for like a month and I can finally say it's complete =D

(This post was last modified: 03-25-2014, 04:36 PM by Mudbill.)
03-25-2014, 04:36 PM
Find




Users browsing this thread: 1 Guest(s)