Project X Forums



It is currently Sun May 12, 2024 9:30 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Looping through all worms each frame - I'm doing it wrong?
PostPosted: Sun Oct 09, 2011 3:34 pm 
Offline
User avatar

Joined: Mon Jun 21, 2010 2:10 pm
Posts: 43
Hi there,

I wanna loop through all worms each frame, checking if they are too far up in the sky and changing their speed to point downwards if that is the case.

However, when checking this script, the compiler can't find the PosY field of foundObj.
Do I have to cast a CWorm out of the found object? I thought this is not needed because there are virtually no "types" in EAX?
Code:
require utils;
CAntiPatience : CObject;

void CAntiPatience::Message(CObject* sender, EMType type, int size, CMessageData* data)
{
    // Calculations each frame
    if (type == M_FRAME)
    {
        // Iterate through all objects
        for (local i = 1; i < Env->Objs.Count; i++)
        {
            // Check if the found object is a worm
            local foundObj = Env->Objs.GetObject(i);
            if (foundObj == CWorm)
            {
                // Check the coordinates
                if (foundObj->PosY > 300) // Problem here: Doesn't find PosY-field
                {
                    foundObj->SpY = -200;
                }
            }
        }
    }
}


Would be nice if you could fix my head :P

Greetings,
Pac-Man


Top
 Profile  
Reply with quote  
 Post subject: Re: Looping through all worms each frame - I'm doing it wron
PostPosted: Mon Oct 10, 2011 3:18 pm 
Offline
PX Developer

Joined: Mon Aug 17, 2009 12:01 pm
Posts: 91
There are types, you don't have to declare them, but you still have to do typecasting.

Code:
require utils;
CAntiPatience : CObject;

void CAntiPatience::Message(CObject* sender, EMType type, int size, CMessageData* data)
{
    // Calculations each frame
    if (type == M_FRAME)
    {
        // Iterate through all objects
        for (local i = 1; i < Env->Objs.Count; i++)
        {
            // Check if the found object is a worm
            local foundObj = CGObject(Env->Objs.Objs[i]));
            if (foundObj is CWorm)
            {
                // Check the coordinates
                if (foundObj->PosY > 300) // Problem here: Doesn't find PosY-field
                {
                    foundObj->SpY = -200;
                }
            }
        }
    }
}


I recommend you to learn from existing scripts. Also, that Message would be never get executed, because CAntiPatience is never instanced. You can override CTurnGame::Message instead, or make an instance of CAntiPatience at first frame.


Top
 Profile  
Reply with quote  
 Post subject: Re: Looping through all worms each frame - I'm doing it wron
PostPosted: Sat Oct 15, 2011 11:21 pm 
Offline
User avatar

Joined: Mon Jun 21, 2010 2:10 pm
Posts: 43
Thanks for the answer. I now override the Message function, but the game now totally locks up at the loading screen (and the chat becomes visible). I could even put a return as the first command inside the override function but it always locks up.
Code:
require utils;

int nextCheck;

// Event each frame
override void CTurnGame::Message(CObject* sender, EMType type, int size, CMessageData* data)
{
    nextCheck--;
    if (nextCheck > 0)
    {
        nextCheck = 30;
        // Calculations each frame
        if (type == M_FRAME)
        {
            // Iterate through all objects
            for (local i = 1; i < Env->Objs.Count; i++)
            {
                // Check if the found object is a worm
                local foundObj = CGObject(Env->Objs.Objs[i]);
                if (foundObj is CWorm)
                {
                    // Check the coordinates
                    if (foundObj->PosY > 1000)
                    {
                        foundObj->SpY = 0;
                    }
                }
            }
        }
    }
}


I already looked at the other scripts but they weren't really helpful to me...


Top
 Profile  
Reply with quote  
 Post subject: Re: Looping through all worms each frame - I'm doing it wron
PostPosted: Sun Nov 06, 2011 6:31 am 
Offline
PX Developer

Joined: Mon Aug 17, 2009 12:01 pm
Posts: 91
You've forgot to put super; .. sry for late answer, i has been inactive for awhile.


Top
 Profile  
Reply with quote  
 Post subject: Re: Looping through all worms each frame - I'm doing it wron
PostPosted: Wed Nov 16, 2011 1:37 pm 
Offline
User avatar

Joined: Mon Jun 21, 2010 2:10 pm
Posts: 43
Just because Steps pulls me to get it to work:
Code:
require utils;

// Event each frame
override void CTurnGame::Message(CObject* sender, EMType type, int size, CMessageData* data)
{
    // Calculations each frame
    if (type == M_FRAME)
    {
        // Iterate through all objects
        for (local i = 1; i < Env->Objs.Count; i++)
        {
            // Check if the found object is a worm
            local foundObj = CGObject(Env->Objs.Objs[i]);
            if (foundObj is CWorm)
            {
                // Check the coordinates
                if (foundObj->PosY > 500)
                {
                    foundObj->SpY = 0;
                }
            }
        }
    }
    super;
}


doesnt work at all
looks like foundObj->SpY = 0; does nothing (printing a message in there works)


Top
 Profile  
Reply with quote  
 Post subject: Re: Looping through all worms each frame - I'm doing it wron
PostPosted: Thu Nov 17, 2011 1:41 pm 
Offline
User avatar

Joined: Sat Nov 27, 2010 12:59 pm
Posts: 346
problem solved by using the PosY override rather than SpY. :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Skin by Lucas Kane