Page 1 of 1

SpawnSwitch Error...

PostPosted: Sun Feb 12, 06 4:37 pm
by Allan
Code: Select all
class SpawnButton expands AAPickupSet;

#exec OBJ LOAD FILE=Ambient
var() Class product;
Var() int CreditCost;

function Frob(actor Frobber, Inventory frobWith)
{
   local DeusExPlayer player;
   local Vector loc;
   local Pickup product;
   
   player = DeusExPlayer(Frobber);

   if (player != None)
   {

      if (player.Credits >= CreditCost)
      {
         PlaySound(sound'Beep5', SLOT_None);
         loc = Vector(Rotation) * CollisionRadius * 0.8;
         loc.Z -= CollisionHeight * 0.7;
         loc += Location;


         if (product != None)
         {
            product.Velocity = Vector(Rotation) * 100;
            product.bFixedRotationDir = True;
            product.RotationRate.Pitch = (32768 - Rand(65536)) * 4.0;
            product.RotationRate.Yaw = (32768 - Rand(65536)) * 4.0;
         }

         player.Credits -= CreditCost;
      }
      else
         player.ClientMessage("Insufficient Funds");
   }
}

Function Prebeginplay()
{ItemName="RPG Shop Summon Switch.";}


This is my spawnswitch code, it works, but i want it to summon a class settable in the properties, and it doesnt summon anything at the moment.(I havent added the code to, i dont know it...)

Can someone give me the code to make a summonable class that you can change in the properties plz :)

PostPosted: Sun Feb 12, 06 5:46 pm
by ~ô¿ô~Nobody~
er.. indeed.. where do you actually summon the class? :shock:


i.e.
something like
Code: Select all
product = Spawn(productClass,,,SpawnLocation);

i guess you get a load of accessed nones

PostPosted: Sun Feb 12, 06 6:23 pm
by Allan
Where in the script?

In the script i borrowed it from (VendingMachine), it was after the line:
Code: Select all
loc += Location;


That code you gave me is what i used, but it doesn't allow variables in the class name place... It's so sad... :'(

PostPosted: Mon Feb 13, 06 7:42 pm
by ~ô¿ô~Nobody~
er.. sure you can use a class variable instead of a static class name :)

here's the code
Code: Select all
class SpawnButton expands AAPickupSet;

#exec OBJ LOAD FILE=Ambient
var() Class product;
Var() int CreditCost;

function Frob(actor Frobber, Inventory frobWith)
{
   local DeusExPlayer player;
   local Vector loc;
//   local Pickup product;  //you can definy local variables that have the same
                            //name like variables declared on the top but i do not recommend this
   //this will do the job
   //but keep in mind!
   //you just declared a variable, in there is no actor saved yet!
   local Pickup spawnProduct;
   
   player = DeusExPlayer(Frobber);

   if (player != None)
   {

      if (player.Credits >= CreditCost)
      {
         PlaySound(sound'Beep5', SLOT_None);
         loc = Vector(Rotation) * CollisionRadius * 0.8;
         loc.Z -= CollisionHeight * 0.7;
         loc += Location;


         //here you create an Actor of zhe class saved in the Product variable
         //and put it in the spawnProduct variable
         spawnProduct=Spawn(product,,,location);
         //now you can access the variable and communicate with the Actor saved in,
         //without getting accessed ones
         if (spawnProduct != None)
         {
            spawnProduct.Velocity = vector(Rotation) * 100;
            spawnProduct.bFixedRotationDir = True;
            spawnProduct.RotationRate.Pitch = (32768 - Rand(65536)) * 4.0;
            spawnProduct.RotationRate.Yaw = (32768 - Rand(65536)) * 4.0;
         }

         player.Credits -= CreditCost;
      }
      else
         player.ClientMessage("Insufficient Funds");
   }
}

Function Prebeginplay()
{
    ItemName="RPG Shop Summon Switch.";
}

PostPosted: Mon Feb 13, 06 11:10 pm
by Allan
Hmm... All seems to be in order now. Thanks for bringing that variable with 2 meanings up, never noticed it :P

but... i get this error now. :

Call to 'Spawn': type mismatch in parameter 1

with "spawnProduct=Spawn(product,,,location); " highlighted... seems it doesnt like that code... :'(

PostPosted: Tue Feb 14, 06 4:58 pm
by ~ô¿ô~Nobody~
ahh yeah

the problem is most possibly
Code: Select all
var() Class product;


if you declare a variable that shall carry a class type, then you also need to specify which is the basic class type that the variable is able to contain

so cahnge it to
Code: Select all
var() Class<Actor> product;

PostPosted: Tue Feb 14, 06 5:09 pm
by Allan
Hooray! After a slight bit of tweaking, it finally works :)

Thanks a million :D