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
"Switch" loops not working as it should
tonitoni1998 Offline
Member

Posts: 163
Threads: 54
Joined: Oct 2012
Reputation: 1
#1
"Switch" loops not working as it should

hey guys. i want the monster to loop 5 nodes all and all over again.

with the use of a switch loop i want the monster to wait 1 sec when it reaches the first path node only at the first loop. so as i understood it i would need a case that says "when i = 1 (because of the first node) set x= 1 (the waiting time). and a default that sets all other cases to x=0.001"

so this would look like this for me:
void reloop_1(string &in asParent, string &in asChild, int alState)
{
    for(int i = 1; i <=5; i++)
    {
    int x;
    switch( i )
    {
    case 1:
        x= 1;
    break;
    default:
        x=0.001;
    }
    AddEnemyPatrolNode("grunt_1", "PathNodeLoop_"+i, x, "");
    }
}

but it waits 1 ec at every node in every loop

When you are looking for someone, to do the scripting for your Custom Story, ask me!
02-18-2013, 06:33 PM
Find
NaxEla Offline
Senior Member

Posts: 415
Threads: 5
Joined: Dec 2012
Reputation: 28
#2
RE: "Switch" loops not working as it should

Don't think this will make a difference, but in this situation, it would probably be better to use an if-else statement.

PHP Code: (Select All)
void reloop_1(string &in asParentstring &in asChildint alState)
{
    for(
int i 1<=5i++)
    {
    
float x;
    if(
== 1) {
        
1.0f;
    }
    else {
        
0.001f;
    }
    
AddEnemyPatrolNode("grunt_1""PathNodeLoop_"+ix"");
    }


Also, I made x a float. That was your problem there. You were trying to set x to 0.001 when it was an int.

In Ruins [WIP]
(This post was last modified: 02-18-2013, 07:22 PM by NaxEla.)
02-18-2013, 07:20 PM
Find
tonitoni1998 Offline
Member

Posts: 163
Threads: 54
Joined: Oct 2012
Reputation: 1
#3
RE: "Switch" loops not working as it should

Yeah i see. I also got an idea how i could do it, that it only waits the first loop, but i dont know it is worth it Tongue

When you are looking for someone, to do the scripting for your Custom Story, ask me!
02-18-2013, 07:40 PM
Find
NaxEla Offline
Senior Member

Posts: 415
Threads: 5
Joined: Dec 2012
Reputation: 28
#4
RE: "Switch" loops not working as it should

You could also just add the first path node, then after one second (using a timer) add the other path nodes.

In Ruins [WIP]
02-18-2013, 07:43 PM
Find
tonitoni1998 Offline
Member

Posts: 163
Threads: 54
Joined: Oct 2012
Reputation: 1
#5
RE: "Switch" loops not working as it should

Yeah when you think about it, there are enought ways to do it.

When you are looking for someone, to do the scripting for your Custom Story, ask me!
02-18-2013, 08:35 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#6
RE: "Switch" loops not working as it should

That's not an issue with script; your code is perfectly fine Smile

A lot of people have this misunderstanding about AddEnemyPathNode. A wait time of 0 does not mean the monster waits for 0 seconds. The monster will pause at any node he is assigned, regardless of the duration being 0 or otherwise. If you want him to loop in a circle, you need to clear his nodes then assign him a new one before he reaches his destination. Use collision callbacks for this. If he reaches his destination node, he will pause before executing his next movement, regardless of the wait time. It sucks, but that's how the game is coded Sad

Edit to expand on your circle loop:
A good way to implement a grunt moving in a circle is to make a circle, and assign him every 2nd or third node along the circle. And before he reaches this node, clear his assigned nodes and add the next one in the loop. This way constantly moves the same direction along the circle; if you just repeatedly add the same node he could potentially turn around and go backwards, depending on how your nodes are set up.

(This post was last modified: 02-18-2013, 10:38 PM by palistov.)
02-18-2013, 10:36 PM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#7
RE: "Switch" loops not working as it should

@OP: The problem in you original code was that the x variable was of type int, so when you assigned "x=0.001", the value got implicitly converted to the nearest integer, which is 0. And, as palistov said, since with AddEnemyPathNode() zero is not zero... you got the idea (I suppose you knew this, since you tried to assign 0.001).
02-20-2013, 01:47 PM
Find




Users browsing this thread: 2 Guest(s)