Author Topic: Setting variables on instantiated objects  (Read 6893 times)

Scobbo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Setting variables on instantiated objects
« on: July 17, 2013, 12:13:45 AM »
Hi,
I have seen this question around however no one seems to have the same problem as me. When a player first logs in, the server creates them a player, a castle, 5 workers, and 5 soldiers. I have to set 2 things about them which I was doing from the same script by saving the return value of the instantiate command. The two big things I need to set are the colour and the owner's name. Even if I have to put a script on the objects that sets these when they are created I don't know how to get the correct value because they are dynamic I can't set them from that script. It has to be set by the server when it receives the login command. I was thinking about having the server send that data to a server only object that newly instantiated castles read and then other object read that castle or whatever (all objects excluding the player and camera are "owned" by the server) the problem is that is more than one player login for the first time at the same time. Is there a better way to go about this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting variables on instantiated objects
« Reply #1 on: July 17, 2013, 02:57:05 AM »
If you want there to be some data associated with a player, the easiest thing to do is encode it in the player's name. The player's name is a string after all.

Scobbo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Setting variables on instantiated objects
« Reply #2 on: July 17, 2013, 09:38:36 PM »
Yes but how do I get the name to the object. After instantiating it I still have to get the player name to the object, regardless of how much data is encoded into it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting variables on instantiated objects
« Reply #3 on: July 18, 2013, 03:06:44 AM »
I don't follow... what does the object's name have to do with it? Each object is owned by a player. You can always retrieve who owns it (TNObject.ownerID). From that you get the player's name (TNManager.GetPlayer), which gives you the player's name with your encoded data.

Scobbo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: Setting variables on instantiated objects
« Reply #4 on: July 18, 2013, 09:00:13 PM »
Oh, I feel like an idiot, I meant the username of the player, that gets assigned to the objects when they are instantiated because the server owns all of the objects except for the player character which is owned by the player. The username and the colour of the object are the ones that get sent to all objects. The name is just the prefab name. I'm sorry, I forgot that was a thing.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting variables on instantiated objects
« Reply #5 on: July 19, 2013, 01:35:49 AM »
Well, if nothing else you can always simply add a new create function that passes the parameters you need inside. You will then only need to add a handler for it (look inside TNManager.OnCreateObject).