Access Arrays


#1

Hello friends!
I have a problem when I try to read the data of “WindowInventory” I am reading the array [0] by the syntax.

var Inventory = measurement?.Value?.WindowInventory?.FirstOrDefault();
Console.WriteLine(Inventory?.Caption);

I do not know how to “Inventory” get the data of the array [1].

I use Sanderling.Sample.Read
SnapCrab_No-0001


#2

you take his index and use element at or default or directly , if you know the item will be always on same position

something similar I used here


#3

If you sure that its allways in this position ,then just use index:

var Inventory = memoryMeasurement?.WindowInventory[1];
if (Inventory != null) Console.WriteLine(Inventory.Caption);

If the position can change from the condition, then use the lambda expression. For example:

var inventory = memoryMeasurement?.WindowInventory?.FirstOrDefault(i => i.Caption == "condition");
if(inventory != null) Console.WriteLine(inventory.LabelText.ToString());


#4

thank you for helping me if you can help me 1 still other threads.
I have trouble with the game control institute,
example “MouseDragAndDrop”

static public MotionResult MouseDragAndDrop(
			this IHostToScript host,
			IUIElement elementToDrag,
			IUIElement destination,
			MouseButtonIdEnum mouseButton)

As far as I’m aware, “IUIElement elementToDrag” and “IUIElement destination” are the locations that should be dragged and the release location.

“MouseButtonIdEnum mouseButton” is the left key, the hold key, and the right mouse button.

“This IHostToScript server” specifies the client receives the control signal.

As I do not know how to create “IHostToScript” it would be great if you wrote me an example of how to control the game and include a comment in your example code.


#5
Sanderling.MouseDragAndDrop(oreHoldItem, DestinationContainer);

it simply click on item , it drag the item to destination container, it release the item
the entire operation , how it find the item ( and where) and destination is in any sample script from Sanderling or any of my scripts. for example this one

if you use Sanderling to create/fix your script, then he shows what you need
if you intend to use A-bot, the VS it ask the elements
an example:
you want to drag one item - vespar - from orehold to item hangar.
then:
you define the location of vespar => the path to item:window inventory ; active ship ; orehold cargo, and you search for item vespar.
you define the location of item hangar: window inventory etc etc : item hangar
if oreholditem = true and itemhangat =true then draganddrop


#6

I have a feeling you misunderstood the problem if not for me to apologize.

The two Sanderling.exe and Sanderling.Sample.Read projects differ a lot.
Sanderling.exe allows you to write code and run it directly while Sanderling.Sample.Read writes the code on VS and then compiles and it depends on many other projects.

It seems that Sanderling.exe has simplified many of the issues, and Sanderling.Sample.Read allows us to control the problem depending on how we write the code.


#7

No, I just forgot you work on Sanderling.Sample.Read :d sorry, my fault
from what I see on source
IHostToScript

it simply get the raw memory readings and rearranges all infos on memory.measurement, parsed measurement and measurement accumulation
I think before , on early versions of optimat it passed by server because now I see

		static public MotionParam MouseDragAndDropOn(
			this IUIElement elementToDrag,
			IUIElement destination,
			MouseButtonIdEnum mouseButton) =>
			new MotionParam
			{
				MouseListWaypoint = new[] { elementToDrag, destination }.Select(uIElement => new MotionParamMouseRegion() { UIElement = uIElement })?.ToArray(),
				MouseButton = new[] { mouseButton },
			};

		static public MotionResult MouseDragAndDrop(
			this IHostToScript host,
			IUIElement elementToDrag,
			IUIElement destination,
			MouseButtonIdEnum mouseButton) =>
			host?.MotionExecute(elementToDrag?.MouseDragAndDropOn(destination, mouseButton));

and the host is simply the “interface”
Anyway since your interest is on reading and using this readings with Sanderling on other bots ( or to modify Sanderling.exe) I supose is better for you to ask Viir or Terpla in pm. because the only ones who understand the mechanismes are Viir and/or Terpla and … dunno if there are more ( and active on forum)


#8

First of all I want to thank kaboonus for his activity on the forum. I am delighted with his patience. Often, precise references to places in the code where you can see examples.
Thank!
Hopefully Viir appreciates you and does not forget to encourage as much as possible.


#9

About your question.
It is not very good to ask a question about MouseDragAndDrop in the subject with the name ’ Access Arrays’. Do you think later someone will find it here?
Anyway, let’s see.


#10

I do not think that I have enough patience to write an example. I will try to explain the algorithm in a simplified way, as I understood it.

kaboonus correctly indicated the code from which I would start the investigation.
Thus, we have an MotionParam object with data: start and end element + mouse button.
How does this data turn into action?

Omit the travel details of our object motion. As a result, he gets here:

var BeginTime = GetTimeStopwatch();
var Result = Motor.ActSequenceMotion(motion.AsSequenceMotion(MemoryMeasurementLast?.Value?.MemoryMeasurement));
var EndTime = GetTimeStopwatch();

First, our MotionParam object (motion) calls AsSequenceMotion().
As far as I understand, this function converts MP to the list of more simple Motion objects:
img
After this bot call ActSequenceMotion() function, which uses WindowsInput.InputSimulator() and converts Motion list to real keystrokes / mouse clicks.
It looks simple, if you do not go into details. :grin:


#11

there is no problem with that :slight_smile: