No Userdata (json) option for AC script?


#1

I think of moving my door to AC script, not sure if it’s possible and going to work.
The first problem i hit is that we cannot set so far i see userdate fro AC script.

Can we really not set userdata for AC script ?
Userdata for AC script would be so usefull, as example for my door. I only need one script. and set the parameters like position etc. by JSON. I get the idea you now need to make for every door as example a new script with all parameters.

But there’s no option on the server ?!

If it’s not implemented , it wuld be a good one to have.


#2

The thing is that the AC script that is running is running as an Assignment Client, So you have to think it a bit differently:

Forexample, If you want to have a AC script that manages doors, it would be a Door Management script. It manages all the doors in the domain, instead of script per each door your have in the domain

The doors will have their own userdata, and the Assignment client receives any broadcasts that happen when the doors are clicked, and manages the doors according to the meta data on the door, instead of the client.


#3

Hmm, i think i get what you mean. yes at the end one script for all doors would be good. But no thanks. not for a long time. It’s night mare to manage that by script.

so 1 script / door.
But now you say, place the door and let the script find the door and read the userdate. could work. But i still need AC userdata to tell the script what door to look for. The door is going to get a long delay until i figured things out.

But still AC json userdate would be very usefull for confgure things.


#4

If willing to jump through some hoops then you could pass configuration options in the URL…

Here is an example AC script that demonstrates:

https://github.com/humbletim/hifi-aux/blob/master/examples/ac-entity-soul/acscript.js

To test it out:

  • create an entity having a particular name and position
  • add an AC script similar to below (specifying name, position and any other params):

acscript.js?config={“name”:“entity-with-soul”,“position”:{“x”:9000,“y”:9000,“z”:9000},“open”:false}

(make sure to get all the JSON quoting right or it won’t be able to parse on the scripting side…)

While “userData” typically exists as JSON, it might be easier to maintain at the domain level by using vanilla key/value querystring params:

acscript.js?name=entity-with-soul&x=9000&y=9000&z=9000&open=false

The same acscript.js can work that way, but you’d have to pull the config from kvargs and interpret the values. Something like:

var config = kvargs;
config.open = config.open !== 'false';
config.position = config; // this works as a Vec3 provided {.x,.y,.z} are present