PDA

View Full Version : Detecting on Screen Text



Lama
10-13-2014, 09:06 PM
I've been trying to figure out how to get a script to know when something has been said by an NPC that doesn't appear in the chatbox, and I stumbled upon the findText() function in the docs.

I also found this unresolved thread asking pretty much the same thing I am: https://villavu.com/forum/showthread.php?t=110143

So what I am trying to do is to let a script proceed when Pauline Polaris at Livid Farm says one of her phrases that resets the activity.

This is my function so far:

function proceed(): boolean;
var
p: TPoint;
i: integer;

begin
if g <= 0 then
writeLn('Waiting for advancement...');

if (findText(p, ['verything''s advance', 'elp, please!'], [UpChars], mainScreen.getBounds())) then
begin
writeLn('The cycle has begun ...');
result := true;
end;

if (findText(p, ['farm''s moved', 'next stage'], [UpChars], mainScreen.getBounds())) then
begin
writeLn('The cycle has begun ...');
result := true;
end;

if (findText(p, ['ore spellcasting', 'required'], [UpChars], mainScreen.getBounds())) then
begin
writeLn('The cycle has begun ...');
result := true;
end;

if (findText(p, ['ime for more work', 'Time for'], [UpChars], mainScreen.getBounds())) then
begin
writeLn('The cycle has begun ...');
result := true;
end;

g := 1;
end;

The docs say the usage of findText() is:
findText(var p: TPoint; txt, fonts: TStringArray; searchBox: TBox)

Which is what I am doing, and I have tried several difference font types. However, the function just doesn't seem to respond to those actions once they happen in game.

Ideas?

Clarity
10-13-2014, 09:18 PM
Use UpCharsEx instead of UpChars :)

http://i.gyazo.com/5655816e3f2a86d55b22333452d554c5.png

UpChars won't return any matches for Pauline's chat since, as you can see, they are quite different fonts.
Best of luck with the added Livid Farm functionality. If you're making a complete script I'm sure the community would be interested!

Edit: I see you said you already tried a bunch of font types. If UpCharsEx didn't work, then perhaps you can use OCR.

OCR Documentation (docs.villavu.com/simba/scriptref/ocr.html)

Tesseract is another option, but I believe it is a nightmare when the background is highly variable.

Lama
10-13-2014, 09:35 PM
Edit: I see you said you already tried a bunch of font types. If UpCharsEx didn't work, then perhaps you can use OCR.

OCR Documentation (docs.villavu.com/simba/scriptref/ocr.html)


I can safely say I have no idea how to implement this for what I want it to do... hmmm (Ideas anyone?)

Clarity
10-13-2014, 10:54 PM
I can safely say I have no idea how to implement this for what I want it to do... hmmm (Ideas anyone?)


repeat
writeln(getTextAtEx(mainscreen.getBounds, 0, 0, 3, clYellow, 5, 'UpCharsEx'));
wait(500);
until false;


Ran it, returned the following when she announced the next stage:



T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .
T h e f a r m ' s m o v e d o n t o i t s n e x t s t a g e .


http://i.imgur.com/y4PFzlH.gif

Returns a pretty accurate string. Especially if you narrow the search box, there's a lot you can do with this :)

Lama
10-15-2014, 12:54 AM
I guess technically I could just tell the script to detect the color of the font, and not really much of what's in it (not a lot of people talk at livid farm, and it wouldn't be a big deal if they did).

Is there a function for detecting a font and it's color, but not necessarily what's in the string? Would I just use a findColorsTolerance(etc) function for mainScreen.getBounds() looking for clYellow? Or whatever value clYellow is.

Kyle
10-15-2014, 01:03 AM
I guess technically I could just tell the script to detect the color of the font, and not really much of what's in it (not a lot of people talk at livid farm, and it wouldn't be a big deal if they did).

Is there a function for detecting a font and it's color, but not necessarily what's in the string? Would I just use a findColorsTolerance(etc) function for mainScreen.getBounds() looking for clYellow? Or whatever value clYellow is.

Just wondering, did you not see Clarity;'s post right above you?

Lama
10-15-2014, 01:21 AM
Just wondering, did you not see Clarity;'s post right above you?

I did, but I tried a few conditional statements regarding the information I got from that, and I couldn't get it to work.

Clarity
10-15-2014, 02:13 AM
I did, but I tried a few conditional statements regarding the information I got from that, and I couldn't get it to work.


if (getTextAtEx = 'T h e f a r m '' s m o v e d o n t o i t s n e x t s t a g e .') then
doSomething();

That didn't work?

Lama
10-15-2014, 10:50 PM
if (getTextAtEx = 'T h e f a r m '' s m o v e d o n t o i t s n e x t s t a g e .') then
doSomething();

That didn't work?

Wait, I don't need the entire

getTextAtEx(mainscreen.getBounds, 0, 0, 3, clYellow, 5, 'UpCharsEx') = 'T h e f a r m '' s m o v e d o n t o i t s n e x t s t a g e .')

Function?

Turpinator
10-15-2014, 11:23 PM
Wait, I don't need the entire

getTextAtEx(mainscreen.getBounds, 0, 0, 3, clYellow, 5, 'UpCharsEx') = 'T h e f a r m '' s m o v e d o n t o i t s n e x t s t a g e .')

Function?



if (getTextAtEx = 'T h e f a r m '' s m o v e d o n t o i t s n e x t s t a g e .') then
doSomething();

That didn't work?

was just pseudo code.