Sign in to follow this  
Followers 0
Sheep_Wizard

Checking to see if a brush is defined

8 posts in this topic

Im trying to check to see if a brush is defined using this code:

if(!isDefined( bullet ))
		bullet = getEnt("bullet", "targetname");

But i get the error - uninitialised variable 'bullet'

 

Does anyone know how to fix this error?

0

Share this post


Link to post
Share on other sites

what're you trying to do?

 

from what I see in that section it's pointless, need some context please

0

Share this post


Link to post
Share on other sites
trap_8()
{
	trig = getEnt("bullet_trig", "targetname");
	while(1)
	{
		trig waittill("trigger", player);
		if(!player.activated)
			thread shootbullet( player );
		wait 0.05;
	}
}

shootbullet( victim )
{
	if(!isDefined( bullet ))
		bullet = getEnt("bullet", "targetname");
	victim.activated = true;
	bulletpos = victim.origin;
	bullet moveTo(bulletpos, 2);
}

Pretty much when someone trigger a trigger it moves the brush towards them, but this can be triggered by multiple people so i need to check if brush is defined i guess

 

I know i can do it other ways but i was just wondering why what iv done doesnt work.

0

Share this post


Link to post
Share on other sites

in the main gsc do something like bullet = undefined;

 

It's because you haven't defined the variable "bullet" so it can't find it :)

0

Share this post


Link to post
Share on other sites

in the main gsc do something like bullet = undefined;

 

It's because you haven't defined the variable "bullet" so it can't find it :)

ok thanks, i thought it would just see it as undefined

0

Share this post


Link to post
Share on other sites

ok thanks, i thought it would just see it as undefined

because @Lossy is a nub in RL and in coding.. and in promod and his anwser is not correct, he just told you to initialize bullet variable with undefined, then check if its defined (which would obviously return false) :davesir:

 

You want to check if brush is present in a map so you need to use GetEntArray() function as it returns count of entities and entity list, use this if you're not sure if entity is present _otherwise_ if you are veeery sure the entity is present use getEnt() [if you call getent but there's no such entity then you'll get script runtime error].

 

This is the code you're looking for:

trap_8()
{
    trig = getEnt("bullet_trig", "targetname");
    while(1)
    {
        trig waittill("trigger", player);
        if( !isPlayer( player ) )
            continue; // actually a trigger can be "triggered" by any entity

        if( isDefined(player.activatedbullet) ) // fixed undefined variable error!
            continue;

        shootbullet( player ); // there are no wait() or waittill() in shootbullet(), no need to thread it
        //also no need for wait(0.05)
    }
}

shootbullet( victim )
{
    bullet = getEntArray("bullet", "targetname");
    if( isDefined( bullet ) && bullet.size > 0 /*is bullet present in map?*/ )
    {
        victim.activatedbullet = true; // now client variable is defined
        bulletpos = victim.origin;
        bullet[0] moveTo(bulletpos, 2);
    }
}
1

Share this post


Link to post
Share on other sites

I know it would retuen false, i just looked at error, commented then left nub. P.S u suck at promod and csgo with that gold nova rank :troll:

 

EDIT: i just seen braxi edit his post 3 times to make sure what he said was correct and he calls me a nub :troll:

0

Share this post


Link to post
Share on other sites

 

because @Lossy is a nub in RL and in coding.. and in promod and his anwser is not correct, he just told you to initialize bullet variable with undefined, then check if its defined (which would obviously return false) :davesir:

 

You want to check if brush is present in a map so you need to use GetEntArray() function as it returns count of entities and entity list, use this if you're not sure if entity is present _otherwise_ if you are veeery sure the entity is present use getEnt() [if you call getent but there's no such entity then you'll get script runtime error].

 

This is the code you're looking for:

trap_8()
{
    trig = getEnt("bullet_trig", "targetname");
    while(1)
    {
        trig waittill("trigger", player);
        if( !isPlayer( player ) )
            continue; // actually a trigger can be "triggered" by any entity

        if( isDefined(player.activatedbullet) ) // fixed undefined variable error!
            continue;

        shootbullet( player ); // there are no wait() or waittill() in shootbullet(), no need to thread it
        //also no need for wait(0.05)
    }
}

shootbullet( victim )
{
    bullet = getEntArray("bullet", "targetname");
    if( isDefined( bullet ) && bullet.size > 0 /*is bullet present in map?*/ )
    {
        victim.activatedbullet = true; // now client variable is defined
        bulletpos = victim.origin;
        bullet[0] moveTo(bulletpos, 2);
    }
}

This worked, thanks :D

0

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0