script: embed loop

Nov 22, 2011 at 11:23 PM
Edited Nov 22, 2011 at 11:24 PM
I have run a test on ConscriptIDE, the following script is working. I just want to know if embed loop is working.
function main()
{
var i,j;

while(true)
{
    i++;
    while(true)
    {
        j++;
    }
}
}
However, while I do it in game environment, I got an error on VerifyResult in HostFunctionPrototype.cs. Here is my modified script. 
/*
 * Troll Script
 */
 
include "EnemyCommon.cns";
 
function main()
{
    InitialiseCommonEnemyData();
    
    while(true)
    {
        var direction, distance;
        
        direction = GetRandom(0, 4);
        distance = 20 + GetRandom(0, 130);
        
        SetDirection(direction);
        switch (direction)
        {
            case DOWN: Move(0, distance);
            case LEFT: Move(-distance, 0);
            case RIGHT: Move(distance, 0);
            case UP: Move(0, -distance);
        }

        while(TextWindow_IsActive()) yield;  // i added
    }
}
I want to break the main loop, so NPC can have other responses to Player or other NPC. Then NPC go back to the main loop.
Nov 22, 2011 at 11:36 PM

I replaced 'TextWindow_IsActive()' with "true".  Few seconds later, they all stopped.  I just try let one/some of them stop, then carry on.

Nov 23, 2011 at 8:54 AM

I'm not sure what you're trying to accomplish here, but bear in mind that the yield simple causes to scripting engine to switch to other scripts that are running in parallael. This can happen even if the yield keyword is not used, but when used it allows you dedicate more execution time to the other scripts. It is mostly useful when you are implementing some sort of synchronisation between scripts.

Nov 24, 2011 at 12:57 AM

Thank you so much, Colin. I am very appreciate your great help.

The Troll Script is managing all trolls. If I want to let one out of its loop, and response my actions. I should identify them respectively in the script. E.g.  try to check who collision with player. And pause its loop. Am I right?

Nov 24, 2011 at 8:45 AM

I think you can make the troll script generic and have an instance of the script running for every troll character. If you define the boolean flags within the scripts' main function, rather than outside, then each script instance should have it's own copy of the flag variables that you can set as you need. For example, if your player interacts with a troll, you can change a flag variable for that troll's script instance, for example so it knows that it needs to stop wandering and turn to face the player instead.

 

Nov 26, 2011 at 3:12 AM

I read all your posts. Still don't have a clear picture about it. But I will keep on working it. This is the best project I ever see.

I checked enmey.cs. It very clearly describes GetPosition and GetPlayerPosition. But how can I get other NPCs' object? So I can let 2 or more NPCs stoped to talk with each other, face to face, while their collion happens.

            if (strFunctionName == "GetPosition")
            {
                AssociativeArray associativeArrayPosition = new AssociativeArray();
                associativeArrayPosition["X"] = this.X;
                associativeArrayPosition["Y"] = this.Y;
                return associativeArrayPosition;
            }
            else if (strFunctionName == "GetPlayerPosition")
            {
                AssociativeArray associativeArrayPosition = new AssociativeArray();
                associativeArrayPosition["X"] = m_player.X;
                associativeArrayPosition["Y"] = m_player.Y;
                return associativeArrayPosition;
            }
Nov 26, 2011 at 3:29 PM
One way to give a character script access to other character objects is to assign id's to all your entities. Then you can set up a function like GetEntityPosition that takes the id as parameter and returns the position of the entity with that id.

On 26 November 2011 04:12, yeeler <notifications@codeplex.com> wrote:

From: yeeler

I read all your posts. Still don't have a clear picture about it. But I will keep on working it. This is the best project I ever see.

I checked enmey.cs. It very clearly describes GetPosition and GetPlayerPosition. But how can I get other NPCs' object? So I can let 2 or more NPCs stoped to talk with each other, face to face, while their collion happens.

            if (strFunctionName == "GetPosition")
            {
                AssociativeArray associativeArrayPosition = new AssociativeArray();
                associativeArrayPosition["X"] = this.X;
                associativeArrayPosition["Y"] = this.Y;
                return associativeArrayPosition;
            }
            else if (strFunctionName == "GetPlayerPosition")
            {
                AssociativeArray associativeArrayPosition = new AssociativeArray();
                associativeArrayPosition["X"] = m_player.X;
                associativeArrayPosition["Y"] = m_player.Y;
                return associativeArrayPosition;
            }

Read the full discussion online.

To add a post to this discussion, reply to this email (conscript@discussions.codeplex.com)

To start a new discussion for this project, email conscript@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Nov 26, 2011 at 4:24 PM

Thanks mate, I will have a try.