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 Help (Request) Moving Shelf using Secrets Books
User01 Offline
Member

Posts: 97
Threads: 30
Joined: Feb 2013
Reputation: 0
#1
(Request) Moving Shelf using Secrets Books

I'm more of a beginner in scripting yet I need this. I've seen those scripts in Custom Stories but I didn't understand them cause they are complicated asf.

The moveable books should be pulled in the right order so that the shelf secret door opens. Pulling the books in the wrong order should reset the puzzle.

All I know is SetMoveObjectState("shelf_secret_door_1", 0); this will open the shelf.


I've created a sample Custom story you can download it here: Moveable Books
05-06-2017, 11:37 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#2
RE: (Request) Moving Shelf using Secrets Books

So you're thinking a puzzle similar to the one in the Archives, except instead of a time limit, they're ordered? So I presume no time limit for this one?

There are several ways of achieving this. First thing I can think of goes like this:

Let's say we have 3 books, book_1, book_2 and book_3. They need to be pulled in the order they are named, but they all look the same.

They each have an area covering the position they need to be in to trigger the pull. These are named area_book_1, area_book_2 and area_book_3.

[Image: 7mgK5VK.png]

Start by adding the collision callbacks:

PHP Code: (Select All)
int bookCounter 1;

void OnStart() 
{
    for(
int i 14i++) 
    {
        
AddEntityCollideCallback("book_"+i"area_book_"+i"PullBook"false1);
    }


PS: If you're unfamiliar with for-loops, here it basically just means that it runs the AddEntityCollideCallback 3 times, with a temporary variable counting 1, 2 and 3 (the variable is named i). I then use that variable to append the current loop number to the names of the books and areas.

The integer variable that I set here will be used later (remember to place it outside the OnStart function).

So now that this callback is created, we need the callback event:

PHP Code: (Select All)
void PullBook(string &in asParentstring &in asChildint alState
{
    
//this should run every time you pull a book out from the shelf.
    //to verify this, enable debug messages for your game and see if this shows up:
    
AddDebugMessage("Pulled a book!"false);


PS: If you don't know how to enable debug messages, see this guide.

If this message doesn't show up when you want it, you may have to tweak the position of the area and the book so that they trigger when they should.

Now, let's put the checks in that PullBook function.

PHP Code: (Select All)
void PullBook(string &in asParentstring &in asChildint alState
{
    if(
asParent == StringSub(asParent0asParent.length() - 1) + bookCounter
    {
        
AddDebugMessage("Pulled the correct book. Number: " bookCounterfalse);
        
bookCounter++;
    } 
    else 
    {
        
AddDebugMessage("Pulled the wrong book. Number: " bookCounterfalse);
        
bookCounter 1;
    }

    if(
bookCounter 3
    {
        
AddDebugMessage("Completed the puzzle!"false);
    }


Ok, so the explanation for this is as follows:

First we check if the number associated with the current book you're pulling matches the value of the bookCounter variable. If the player pulls book_2 first, then that will not match the bookCounter variable, but if they pull book_1, then it will. If it matches, it runs the following section. If not, it runs the else-section.

If they pull the correct book, the bookCounter increases by one, so that it now matches the digit on the next book.

If they pull the wrong book, the bookCounter variable resets back to 1 and the player has to start over.

After they've pulled the first book, bookCounter becomes 2 (still not enough for the completed if-statement). After the second book, it becomes 3 (still not). After the third and final book, the value is increased to 4, which is more than 3, which is what the final if-statement checks for. Once you reach this section, the puzzle is complete.

That's the magic of it all. But remember, there's more you need to do in terms of resetting the books when they fail it, and disabling the event when they complete it so that it doesn't happen multiple times. Scripts you may find useful for this are ResetProp, SetPropStaticPhysics, perhaps AddPropForce, and RemoveEntityCollideCallback.

PS: If you're curious about the first if-statement and what it really means, remember that asParent is a string reference to the parent entity that triggered this current event (for example book_1). StringSub is a function that creates a new sub string from another string. I put asParent into it, and told it to create a new string from index 0 through the last index minus 1. Basically it took book_1 and removed the last character, and then it added the bookCounter instead.

You can read about all the functions on the wiki.

I wrote this out of visualization and memory so I may have overlooked something. Hopefully not.

(This post was last modified: 05-09-2017, 12:25 PM by Mudbill.)
05-06-2017, 02:15 PM
Find
User01 Offline
Member

Posts: 97
Threads: 30
Joined: Feb 2013
Reputation: 0
#3
RE: (Request) Moving Shelf using Secrets Books

I haven't enabled debug messages, though.
However, I can't put both callback events, so I just took the last one. I added the SetMoveObjectState function when the puzzle is supposed to be completed to see if this is working. But it didn't.
(This post was last modified: 05-06-2017, 05:47 PM by User01.)
05-06-2017, 05:46 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: (Request) Moving Shelf using Secrets Books

I meant for the last PullBook function to replace the one above it. The first one is just a demonstration of how it's supposed to look before we put the script into it.

Can you post the complete script you have and perhaps a screenshot of the map? I also highly suggest you enable debug messages as it makes it much easier to debug.

05-06-2017, 08:13 PM
Find
User01 Offline
Member

Posts: 97
Threads: 30
Joined: Feb 2013
Reputation: 0
#5
RE: (Request) Moving Shelf using Secrets Books

PHP Code: (Select All)
int bookCounter 1;

void OnStart() {
    for(
int i 14i++) {
        
AddEntityCollideCallback("book_"+i"area_book_"+i"PullBook"false1);
    }


void PullBook(string &in asParentstring &in asChildint alState) {
    if(
asParent == StringSub(asParent0asParent.length() - 1) + bookCounter) {
        
AddDebugMessage("Pulled the correct book. Number: " bookCounterfalse);
        
bookCounter++;
    } else {
        
AddDebugMessage("Pulled the wrong book. Number: " bookCounterfalse);
        
bookCounter 1;
    }

    if(
bookCounter 3) {
        
AddDebugMessage("Completed the puzzle!"false);
        
SetMoveObjectState("shelf_secret_door_1"1);
    }


In front of each book is a script area.
[Image: vkc85e7g.png]
(This post was last modified: 05-06-2017, 08:21 PM by User01.)
05-06-2017, 08:18 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#6
RE: (Request) Moving Shelf using Secrets Books

You didn't get to check the debug messages, eh? That would give us a hint of where it stops working.

You can upload the CS and I'll test it.

05-07-2017, 12:14 AM
Find
User01 Offline
Member

Posts: 97
Threads: 30
Joined: Feb 2013
Reputation: 0
#7
RE: (Request) Moving Shelf using Secrets Books

Well, I tried setting up the development enviroment by following these steps. In the end I couldn't open the debug menu and therefore I don't see debug messages. Guess something went wrong, though. Would be easier if there was a video demonstration of it. However, I reinstalled the game to make sure nothing broke.

Here's the CS: https://en.file-upload.net/download-1248...s.rar.html
(This post was last modified: 05-07-2017, 09:31 AM by User01.)
05-07-2017, 09:29 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#8
RE: (Request) Moving Shelf using Secrets Books

Well, I opened the map and saw that you didn't name your books correctly. They are named book_moveable_1 instead of book_1 as the script asks for.

I tested it and now it works just fine.

I do have a video on setting up a dev environment, but it's for Mac. It's not very different though, so you should be able to figure it out pretty easily. The only difference is the file locations.

https://www.youtube.com/watch?v=ktOU_dAvezo

(This post was last modified: 05-07-2017, 02:05 PM by Mudbill.)
05-07-2017, 02:03 PM
Find
Radiance Offline
Senior Member

Posts: 319
Threads: 34
Joined: Aug 2015
Reputation: 5
#9
RE: (Request) Moving Shelf using Secrets Books

What does this mean :

//string &in asParent//
05-07-2017, 08:55 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#10
RE: (Request) Moving Shelf using Secrets Books

If it starts with 2 forward slashes, then it's a comment and has no effect on the script. But that's not what you asked, eh?

This part is used inside the parameters of a function. The first part specifies the data type of the parameter, the second part is optional but has to do with AngelScript and how it copies and transfers information between the input and output values (you don't necessarily need to know what this means), and the last part is the given name of the parameter.

Have an example:

PHP Code: (Select All)
void MyFunc(int value) {
    
DoSomething(value);


This function named MyFunc takes an integer parameter. Therefore if you want to call this function, you must satisfy that.

PHP Code: (Select All)
void OnStart() {
    
MyFunc(5);


Here we give MyFunc an int with the value of 5. What happens is that MyFunc now takes that value of 5 and does something with it.

The &in part I can't really explain because I don't properly understand it myself, but I've read about it on the AngelScript wiki, and it seems to be specific to this language. It can be &in, &out or &inout for input, output or both, respectively. I believe it handles the scope of the variables given to the function.

05-07-2017, 09:33 PM
Find




Users browsing this thread: 1 Guest(s)