Author Topic: value always returns false? [SOLVED]  (Read 2730 times)

In this case, when checking to see if %obj is an object, it returns false even when what I believe to be the object (a brick) is there.
// Activate Data
function JobBrickData::Activate(%datablock, %client, %obj)
{
   if (!isObject(%obj))
   {
      return;
   }

      
   messageClient(%client, '', "\c3Employment Office");
   messageClient(%client, '', "\c31. \c6Job list");
   messageClient(%client, '', "\c32. \c6Specify job");
   messageClient(%client, '', "\c33. \c6Get job");
   messageClient(%client, '', "\c34. \c6Apply for Shop-Keeping License");
   %client.activateDatablock = %datablock;
   %client.activateState = 0;
   return true;
}

the function for that brick is defined here and it IS in a package
function Player::activateStuff(%player)
   {
      Parent::activateStuff(%player);
      
      // Retreive target
      %obj = %player.GetObjectFromPOW($TypeMasks::fxBrickObjectType);
      
      if (!isObject(%obj))
         return 0;
      
      %client = %player.client;
      if (!%client.isInRP())
         return 0;
      // Avoid player press too many times
      if (!%client.CheckLastAction(%obj))
         return 0;
      
      // Brick
      if (%obj.getType() & $TypeMasks::fxBrickObjectType)
      {
         %datablock = %obj.getDataBlock();
         
         // Info brick
         if (%datablock.isInfoBrick)
         {
            %mods = %client.RPGUIMods;
            %mod = strlwr(%datablock.mod);
            %cmd = %datablock.guiCmd;
            %name = %datablock.getName();

            if (isFunction(%name, "Activate"))
            {
               if (%datablock.Activate(%client, %obj) != false)
               {
                  messageClient(%client, '', "\c30. \c6Exit");
                  %client.ThrowLastActive();
               }
            }

            // Invalid
            else
            {
               commandToClient(%client, 'centerPrint', "\c2Invalid clickable brick.", 2);
            }
            %client.lastAction = $sim::time;
         }
      }
      return 1;
   }
« Last Edit: November 16, 2014, 03:33:14 PM by Gordo12699 »

Is %name returning JobBrickData and if so then does isFunction(%name, "Activate") actually checking for JobBrickData::Activate? It might be better to do isFunction(%name @ "::Activate")

does isFunction(%name, "Activate") actually checking for JobBrickData::Activate? It might be better to do isFunction(%name @ "::Activate")
No, the former is correct

The problem is that Activate isn't the correct name, it's onActivate

EDIT: Those function arguments are wrong too
The correct arguments are: the brick object, the clicking player, the clicking client, and two vectors that I'm not sure what they are
« Last Edit: November 16, 2014, 02:02:52 PM by Headcrab Zombie »

No, the former is correct

The problem is that Activate isn't the correct name, it's onActivate
it does explicitly call %datablock.Activate though

it does explicitly call %datablock.Activate though
This doesn't even exist on my clean install
[img ]http://i.imgur.com/M8KDfL0.png[/img]
(The first one is the brick object)


EDIT: Oh, his code calling an activate function that he defined
i was confused what his problem was I guess


Moving forward:

%obj = %player.GetObjectFromPOW($TypeMasks::fxBrickObjectType);
Show us this function

Actually, what are you trying to do that you need to overwrite player::activatestuff and create your own activate method? What's wrong with the already made fxdtsbrick::onActivate?
« Last Edit: November 16, 2014, 02:09:35 PM by Headcrab Zombie »

Moving forward:
Show us this function

Actually, what are you trying to do that you need to overwrite player::activatestuff and create your own activate method, instead if just parenting the already existing fxdtsbrick::onActivate?

// Get object from point of view
function Player::GetObjectFromPOW(%player, %mask)
{
   %mask = %mask || $TypeMasks::all;
   %point = %player.getEyePoint();
   %obj = containerRayCast(%point, vectorAdd(vectorScale(vectorNormalize(%player.getEyeVector()), 4), %point), %mask, %player);
   return firstWord(%obj);
}


I'm trying to check to see if the brick is an object (since it's an admin only brick, it's supposed to disappear when a non-admin plants it) and stop the function from working if the brick is not in existence (when it deletes)
« Last Edit: November 16, 2014, 02:11:15 PM by Gordo12699 »

Quote
Actually, what are you trying to do that you need to overwrite player::activatestuff and create your own activate method? What's wrong with the already made fxdtsbrick::onActivate?


I'm trying to check to see if the brick is an object
But the default methods already do this
::ActivateStuff can't call ::onActivate if there's nothing there to call it on
If the raycast doesn't find a brick, then there's nothing to call onActivate on
And if it did somehow call it on a nonexistant object, it would never reach the onactivate function, it would just report "Unable to find object" straight away
« Last Edit: November 16, 2014, 02:22:55 PM by Headcrab Zombie »

But the default methods already do this
::ActivateStuff can't call ::onActivate if there's nothing there to call it on
If the raycast doesn't find a brick, then there's nothing to call onActivate on
And if it did somehow call it on a nonexistant object, it would never reach the onactivate function, it would just report "Unable to find object" straight away

The thing is, the non-admin players plant the brick and click it immediately before it deletes itself, allowing players to use the brick and the Activate functions. I'm trying to check to see if the brick is gone when the players are already using the brick and its Activate functions.

The thing is, the non-admin players plant the brick and click it immediately before it deletes itself
How about preventing them from planting the brick in the first place?

I'm trying to check to see if the brick is gone when the players are already using the brick and its Activate functions.
The default activateStuff function already does almost everything you're trying to do.
The only thing you're trying to do that it doesn't already do is add an isObject check inside the brick method, which will never return because you can't get inside the method if the object you're calling it on doesn't exist. The brick either exists, enters the method, and passes the isObject check, or doesn't exist, and never enters the method. Unless you call .delete inside the method before the if check, there are no other cases. It doesn't logically make sense for their to be any other cases
« Last Edit: November 16, 2014, 02:50:36 PM by Headcrab Zombie »

How about preventing them from planting the brick in the first place?
The default activateStuff function already does almost everything you're trying to do.
How would I go about preventing them from planting the brick in the first place without removing the brick?

How would I go about preventing them from planting the brick in the first place without removing the brick?
Package serverCmdPlantBrick
Check the value of client.player.tempbrick.getDa tablock()
Return if datablock matches admin only datablock, and not admin
« Last Edit: November 16, 2014, 02:46:45 PM by Headcrab Zombie »

Package serverCmdPlantBrick
Check the value of client.player.tempbrick.getDa tablock()
Return if datablock matches admin only datablock, and not admin
I will let you know how this goes. Thank you!

Also a small thing
In your original function in the op you don't return any value, and then compare it to false
Although torque will allow this, and interpret null (if torque even calls it null) as false, it's still good practice to return false instead of nothing
Most other languages will explode if you try to do this