Game Development Community

Changing playerdata values on the run

by Josiah Wang · in Torque Game Engine · 02/09/2005 (4:06 pm) · 8 replies

In my game, I have an item that when used (like a healthkit) will increase the speed of the player for 5 seconds. Here's my code so far:

function powerup_speed::onUse(%this,%user)
{
      %user.decInventory(%this,1);
      //%user.applyRepair(%this.repairAmount);
      %user.setTranquilized(0.02);

      %user.runForce = 180 * 90;
      %user.jumpForce = 60.0 * 90;
            
      
      if (%user.client)
         messageClient(%user.client, 'MsgHealthKitUsed', '\c2Speed Power-Up Applied');
         
      schedule(5000,%user,setPowerupSpeedDone,%user);

}

function setPowerupSpeedDone(%user)
{
 %user.setTranquilized(0.0);
 messageClient(%user.client, '', '\c2Finished Undizzy');
}

however, i tried running that, and my upgrades (run force and jump force) did not apply. My question here is how I can get these 'upgrades' to apply to my player, and how i can reset them back to what is defined in the PlayerBody datablock

thanks!

#1
02/09/2005 (5:19 pm)
You can't update datablock values on the fly. You'll have to find some other way of modifying the players speed. The reason for this is there is only one copy of a datablock that is shared to every object instance that uses it. Since there can potentially be more then 1 player object in the game this saves bandwidth since we can use just one copy of a datablock to share between them.
#2
02/09/2005 (5:26 pm)
Maybe this
will help
#3
02/09/2005 (5:45 pm)
Josiah: this should be exactly what you are looking for. Unfortunately, you'll have to convert the old console access style used in that resource to the newer consoleMethod method... but that could just be a good lesson in learning Torque!

Stephane
#4
02/12/2005 (7:33 pm)
Hello all, new to the boards and just starting to get my head on straight with scripting. I was wondering if this inability to change fields is the same with objects not instantiated from datablocks. If I were to manually create a player object not associated with any datablock, would I then be able to alter the fields?
#5
02/12/2005 (7:36 pm)
Good question.

You should probably start it in its own thread though
#6
02/12/2005 (7:56 pm)
<-- Is an obsessive TGE scripter

In your example code you were also editing the player, which doesn't (unless you added it into the engine) have any functions except for 3: client, datablock, and some other one I forgot :) You can change player level values on the fly (switch the used datablock) which could be used to create a limited speed up system (switch to speeded up DB at start, switch to slowed down later)

I used a fuzzy version of this to do a player stat system, where the player was set to a datablock with their name on it, the datablock was updated based on the player's stats, etc. Err... confuzing arent I?

Not sure if I cleared anything up, but... yeah... :)

Ishbuu
#7
03/21/2005 (11:34 am)
Wow, after a month, I finally understand your post (jk) actually i didn't notice your reply, Ishbuu

I thought about that too, but that would mean I can't change more than one value at a time (at least, economically). If I were to change both player speed and something like energy (*shrug, just an example*), I would need a lot DBs: one for normal speed and normal energy, one for normal speed and more energy, one for normal speed and less energy, one for more speed and less energy, etc etc...

Something I *thought* might be possible is making it add something in the playerbody DB itself. Something like this in player.cs (take from PlayerBody:

mass = 1000 + %massVariable;
   drag = 0.3;
   maxdrag = 0.4;
   density = 10;
   maxDamage = 100 + %maxDamageVariable;
   maxEnergy =  60 + %maxEnergyVariable;
   repairRate = 0.33 + %repairRateVariable;
   energyPerDamagePoint = 75.0;
etc etc....

would that work?


[edit]
DOH. Just read stephane's post. nvm.
[/edit]
#8
12/09/2006 (2:16 am)
There are several links up there, which one are you looking for an update for?

If it is the script above, then that will work in all versions.