• Hail Guest!
    We're looking for Community Content Contribuitors to Stratics. If you would like to write articles, fan fiction, do guild or shard event recaps, it's simple. Find out how in this thread: Community Contributions
  • Greetings Guest, Having Login Issues? Check this thread!
  • Hail Guest!,
    Please take a moment to read this post reminding you all of the importance of Account Security.
  • Hail Guest!
    Please read the new announcement concerning the upcoming addition to Stratics. You can find the announcement Here!

[Tech Help] Command Line Script to Store a Variable Permanently

Llewen

Grand Inquisitor
Stratics Veteran
Stratics Legend
Campaign Supporter
I'd like to make a command line script that can store the name of an object permanently to use in other command line scripts. What I want to do is run the script, it presents a target, I can target a pet, it stores the name of that pet in a variable, which I can then use in another script instead of having to edit the script every time I change pets.
 

petemage

Babbling Loonie
Stratics Veteran
Stratics Legend
UNLEASHED
Sorry, not gonna try to put this into command script items, but what you want to do is:

1)
Code:
RequestTargetInfo()
will give you an cursor to select (request) an target. That's the easy part.

2) To get the response (target) you have to register to the SystemData.Events.TARGET_SEND_ID_CLIENT event. This is accomplished by
Code:
WindowRegisterEventHandler("MyWindow", SystemData.Events.TARGET_SEND_ID_CLIENT, "MyWindow.RequestTargetInfoReceived")
3) Once you selected a target,
Code:
MyWindow.RequestTargetInfoReceived
will be called and you can use
Code:
SystemData.RequestInfo.ObjectId
to get the Id of the selected object (i.e. your pet)

4) To get from the id to the pet's name, you need to register windowdata for pets with
Code:
RegisterWindowData(WindowData.Pets.Type, 0)
and then you can loop through all pets to find the one you targeted:
Code:
if (WindowData.Pets.PetId ~= nil ) then	
		local petSize = table.getn(WindowData.Pets.PetId)
		if (petSize > 0) then
			for numPet = 1, petSize do
				local mobileId = WindowData.Pets.PetId[numPet]
								...
5) To persist between logouts, you can use
Code:
Interface.SaveString( settingName, settingValue )
to save the pets name and use LoadString to get it back. You can also store the id with StoreNumber/LoadNumber.

Ideally you want to have a window for 2) and 3) since you don't want to mess with other target cursors of other parts of the UI. You could quick n dirty register to "Root" instead of "MyWindow", but if you cancel a request or forget to unregister the response handler that might screw things up a bit.

If you not gonna put it into a mod, I doubt you gonna have fun with this :p
 
Last edited:

Llewen

Grand Inquisitor
Stratics Veteran
Stratics Legend
Campaign Supporter
Thanks. Ya, that's a bit complex for a command line script... I think I'm stuck with editing my command line whenever I change loose pets. Not a big deal really.
 
Top