Activating items (i.e. MP3 (on) and MP3 (off))

I’m trying to create a new tool/weapon with the ability to turn on and off, similar to the tactical(shock) tonfa or the chainsaw. Problem is, I have no idea how to make it so activating it turns it on/off. I have the rest of it coded just fine, that’s the only thing I can’t figure out.

I dug around in the JSONs quick, and it looks like there’s a property just for this kind of thing. If you want it to do something special while it’s on, you’ll probably need to edit the code, but just making an item turn on and off looks easy.
An excerpt from the flashlight item JSON:

...
"use_action": {
    "type": "transform",
    "msg": "You turn the flashlight on.",
    "target": "flashlight_on",
    "active": true,
    "need_charges": 1,
    "need_charges_msg": "The flashlights batteries are dead."
}

And flashlight_on:

...
"max_charges": 100,
"initial_charges": 100,
"charges_per_use": 0,
"turns_per_charge": 15,
"ammo": "battery",
"revert_to": "flashlight", (assuming this is what turns a flashlight off if it runs out of batteries)
"use_action": {
    "type": "auto_transform",
    "msg": "You turn the flashlight off.",
    "target": "flashlight"
}

Also, the Radio item has this in its On state:

"use_action": "RADIO_ON"

I assume that means that whenever the radio uses a charge it performs the “RADIO_ON” action in the code.

I just tried that but i got this–

[spoiler]src/game.cpp[220]: Error loading data from json: ./data/mods/EW_Pack - Copy/ew_weapons.json: line 288:20: expecting string but got ‘{’

"revert_to" : "null",
"category": "weapons",
"use_action" : {
                       ^

	"type": "transform",
    "msg": "You turn the energy sword on.",[/spoiler]

My first guess would be you forgot to close that second pair of brackets {} or left an extra comma somewhere.
Also, that space between “use_action” and the : might be causing problems.

Just look for any typos and try to keep your indentation, spacing, line breaks, item order, etc. consistent with the rest of the file (this should make typos and other errors more obvious).

No that didn’t fix it. I also tried using different things like “” () [] and it didn’t fix it.

Please post your actual json, the error messages by themselves aren’t that helpful.

Just in case you haven’t noticed yet, when there is an item that can be turned on/off that usually means that there are two seperate entries of that item, one where it’s on and one where it’s turned off. Using the item transforms it into the other version and vice versa.

You probably knew this already, but maybe it helped just a little.

You are using an experimental build, are you? Because that transform feature thing is not present in 0.A - the error (“expecting string”) looks suspiciously like the game does not even try to load that json object.

I see that’s in weapons.json. You actual want to add it as a tool instead. Take a look at Rising Sun (off) and (on) entries for a good example.