It is currently April 23rd, 2024, 6:55 am

AI lua troubles

Get help with creating, editing & fixing problems with skins
hashtaghashtag9967
Posts: 8
Joined: August 26th, 2017, 12:38 pm

AI lua troubles

Post by hashtaghashtag9967 »

I'm attempting to create a "AI" (not really just something with pre-made responses to user input) and to do so i need to read the input text of the user, witch is proving to be quite difficult as i'm extremely new to programing for rainmeter.


this is the code, at the moment all i want is a text box that responds with pre made inputs.

Code: Select all

[Rainmeter]
Update=30
DynamicWindowSize=1
[Variables]
FirstVar=!WriteKeyValue
SecondVar=Speak To P.U.N.
FontSize=14
[MeterBackground]
Meter=Image
SolidColor=008fb3
W=250
H=105
[MeasureInput]
Measure=Plugin
Plugin=InputText
SolidColor=76A0E8FF
FontColor=255,255,255,255
FontFace=Seqoe UI
StringStyle=Italic
FontSize=#FontSize#
X=5
Y=5
H=25
W=240
DefaultValue="Change Me!"
Command1=!WriteKeyValue Variables FirstVar "$UserInput$" "#CURRENTPATH#InputText.inc"
Command2=!Refresh #CURRENTCONFIG#
Command3=!SetVariable SecondVar "$UserInput$" Y=40 DefaultValue=""
Command4=["$UserInput$"] Y=75 DefaultValue="Text file path and name"





[MeterSetVariable]
Meter=String
X=5
Y=-60R
FontSize=15
FontColor=255,255,255,255
AntiAlias=1
DynamicVariables=1
Text=#SecondVar#
LeftMouseUpAction=!CommandMeasure "MeasureInput" "ExecuteBatch 3"







[RESPONDINGTEXT]
Meter = string
FontSize=15
X=5
Y=-60R
FontColor=230,250,155
TEXT=derp

[TEXTSCAN]
Measure=String
String=[MeterSetVariable]

IfMatch=hi
IfMatchAction=[!SetOption RESPONDINGTEXT Text "hi hashtag"]



pls help im slowly going insane :handtohead: :handtohead: :handtohead: :handtohead: :handtohead:
Last edited by hashtaghashtag9967 on August 26th, 2017, 11:31 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AI troubles

Post by jsmorley »

hashtaghashtag9967 wrote:I'm attempting to create a "AI" (not really just something with pre-made responses to user input) and to do so i need to read the input text of the user, witch is proving to be quite difficult as i'm extremely new to programing for rainmeter.


this is the code, at the moment all i want is a text box that responds with pre made inputs.

pls help im slowly going insane :handtohead: :handtohead: :handtohead: :handtohead: :handtohead:
There are are couple of problems with that, like

Code: Select all

[TEXTSCAN]
Measure=String
String=[MeterSetVariable]
A meter has no "value". You can't set the value of a String measure to the "value" of a String meter. You can only use the value of a measure in a [SectionVariable].

But to be honest, this whole thing has a fatal flaw. The problem is that IfMatch does not support any kind of "if / then / elseif / else" construct. Each IfMatch option is a standalone question that can only ask "is this true?" and set one of either "it is", or "it isn't". Presumably you want some IfNotMatch action, like "I didn't understand". So if the first IfMatch is "true", it will set the IfMatchAction. If then the second IfMatch is "false", and of course it will be, that one will set the IfNotMatch action of "I didn't understand".

There is no easy way to say "If I said this, do that, if I said this do that, if I said this, do that. If I said none of those, do something else."

So aside from the boatload of IfMatch[N] actions you would need to flesh this out, it's going to be difficult to get graceful behavior.

I'd recommend doing this in Lua where you can in fact have "if / then / elseif / else" thinking, and simply have a table of your "input snippets" like "hi", that return the response, like "Hi there, nice to see you again". If no match is made on the table, you return "I didn't understand".

Getting the "AI" right is going to be a challenge, you are going to to want to for example search on "hi " and not "hi", so you you don't have it respond to "Hitler was a great guy, and I really miss him" with "Hi, nice to see you". Even the most basic AI, much less something like Google Now or Cortana, attempt to get the "sense" of the input, which is not just based on keywords, but complicated weighting and the order of words in a sentence, and who knows what else.

You might want a different response to "Hi there, nice to meet you", than you do to "Hi little girl, how about some free candy in my van?" If you don't, then your trip to insanity is pretty much complete isn't it...

But having said that, here is something that is loosely based on what you had, that at least "works".

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
FontSize=14

[MeterBackground]
Meter=Image
SolidColor=008fb3
W=250
H=105

[MeterPrompt]
Meter=String
X=5
Y=60
FontSize=15
FontColor=255,255,255,255
AntiAlias=1
DynamicVariables=1
Text=Speak to P.U.N.
LeftMouseUpAction=[!SetOption RESPONDINGTEXT Text "I'm listening"][!UpdateMeter RESPONDINGTEXT][!Redraw][!CommandMeasure "MeasureInput" "ExecuteBatch 1"]

[MeasureInput]
Measure=Plugin
Plugin=InputText
SolidColor=76A0E8FF
FontColor=255,255,255,255
FontFace=Seqoe UI
StringStyle=Italic
FontSize=#FontSize#
X=5
Y=60
H=25
W=240
OnDismissAction=[!SetOption RESPONDINGTEXT Text "Welcome"][!UpdateMeter RESPONDINTEXT][!Redraw]
Command1=[!SetOption TEXTSCAN String "$UserInput$"][!EnableMeasure TEXTSCAN][!UpdateMeasure TEXTSCAN][!UpdateMeter RESPONDINGTEXT][!Redraw]

[RESPONDINGTEXT]
Meter = string
FontSize=15
X=5
Y=5
W=240
ClipString=1
FontColor=230,250,155
TEXT=Welcome

[TEXTSCAN]
Measure=String
IfMatch=(?i)hi
IfMatchAction=[!SetOption RESPONDINGTEXT Text "Hi, nice to see you"]
IfNotMatchAction=[!SetOption RESPONDINGTEXT Text "I didn't understand"]
Disabled=1
UpdateDivider=-1
DynamicVariables=1
GIF.gif
You do not have the required permissions to view the files attached to this post.
hashtaghashtag9967
Posts: 8
Joined: August 26th, 2017, 12:38 pm

Re: AI troubles

Post by hashtaghashtag9967 »

Ok thanks so much, wasn't really going for something that knows how to formulate speech patterns and reconsise different questions i was looking for something to take something like "open chrome" and then it would do it and say a message like "ok opening chrome" and open chrome, The solution you gave works great for this purpose, thanks!!! now ill be slightly less crazy. :D
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AI troubles

Post by jsmorley »

Glad to help.
hashtaghashtag9967
Posts: 8
Joined: August 26th, 2017, 12:38 pm

Re: AI troubles

Post by hashtaghashtag9967 »

Terably sorry to bother you again but after doing some research on lua scripting i have come to the realization that is is far superior to the clunky rainmeter system. I think i have the code correct but it wont display the out put. (side note: the help page on the lua/rainmeter thing is about as helpful as a bag of rocks)

here is the rainmeter ini file:

Code: Select all

[Rainmeter]
Update=10
DynamicWindowSize=1

[Variables]
FontSize=14

[MeterBackground]
Meter=Image
SolidColor=008fb3
W=250
H=105

[MeterPrompt]
Meter=String
X=5
Y=60
FontSize=15
FontColor=255,255,255,255
AntiAlias=1
DynamicVariables=1
Text=Speak to P.U.N.
LeftMouseUpAction=[!SetOption RESPONDINGTEXT Text "I'm listening"][!UpdateMeter RESPONDINGTEXT][!Redraw][!CommandMeasure "MeasureInput" "ExecuteBatch 1"]

[MeasureInput]
Measure=Plugin
Plugin=InputText
SolidColor=76A0E8FF
FontColor=255,255,255,255
FontFace=Seqoe UI
StringStyle=Italic
FontSize=#FontSize#
X=5
Y=60
H=25
W=240
OnDismissAction=[!SetOption RESPONDINGTEXT Text "Welcome"][!UpdateMeter RESPONDINTEXT][!Redraw]
Command1=[!SetOption TEXTSCAN String "$UserInput$"][!EnableMeasure TEXTSCAN][!UpdateMeasure TEXTSCAN][!UpdateMeter RESPONDINGTEXT][!Redraw]


[script]
Measure=script
scriptFile=lua.lua


[RESPONDINGTEXT]
Meter = string
FontSize=15
X=5
Y=5
W=240
ClipString=1
FontColor=230,250,155
TEXT=Welcome
here is the .lua

Code: Select all

function Initialize()

inputtext = null

outputtext = "waiting for request...."



end

function Update()

	inputtext = MeasureInput:Getoption('group, none')



	if inputtext = "hi" then outputtext = 'hello user'
		elseif inputtext = hello then outputtext = 'hi user'
		else outputtext = 'sorry i dont understand'


	end
	
	
	SKIN:Bang('!SetOption', 'RESPONDINGTEXT', 'Text', 'hello world')
	
	SKIN:Bang('[!UpdateMeter "RESPONDINGTEXT"]')
	SKIN:Bang('[!Redraw]')
	
	


end
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AI lua troubles

Post by jsmorley »

First off, let me offer this:

https://forum.rainmeter.net/viewtopic.php?f=99&t=26462

There was really a lot wrong with your script, more than I think it is worth digging into piecemeal. That link above can really help to get you off and running with interfacing Rainmeter and Lua.

In defense of the documentation, it should be understood that it documents, and on the contrary I think fairly well, the interface between Lua and Rainmeter. What it does not attempt to do, nor should it, is teach you the Lua language. While it is one of the easiest languages out there to learn, that's on you...

In addition, most of our documentation is in the form of a "reference", not a "tutorial". I, and others, have tried to add some narrative help, more like tutorials, in various Tips & Tricks posts on the forum. Browsing through those can often be a big help.

Make no mistake, I give you huge credit for jumping in with both feet into something new, and you were pretty close to getting it right.

Having said that, I did fix up your skin and script so they work, and you might be able to glean some ideas from this.

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
FontSize=14

[MeasureScript]
Measure=Script
ScriptFile=Lua.lua
Disabled=1

[MeterBackground]
Meter=Image
SolidColor=008fb3
W=250
H=105

[RESPONDINGTEXT]
Meter = string
FontSize=15
X=5
Y=5
W=240
ClipString=1
FontColor=230,250,155
TEXT=Welcome

[MeterPrompt]
Meter=String
X=5
Y=60
FontSize=15
FontColor=255,255,255,255
AntiAlias=1
DynamicVariables=1
Text=Speak to P.U.N.
LeftMouseUpAction=[!SetOption RESPONDINGTEXT Text "I'm listening"][!UpdateMeter RESPONDINGTEXT][!Redraw][!CommandMeasure "MeasureInput" "ExecuteBatch 1"]

[MeasureInput]
Measure=Plugin
Plugin=InputText
SolidColor=76A0E8FF
FontColor=255,255,255,255
FontFace=Seqoe UI
StringStyle=Italic
FontSize=#FontSize#
X=5
Y=60
H=25
W=240
OnDismissAction=[!SetOption RESPONDINGTEXT Text "Welcome"][!UpdateMeter RESPONDINTEXT][!Redraw]
Command1=[!CommandMeasure MeasureScript "DealWithInput('$UserInput$')]
Lua.lua:

Code: Select all

function DealWithInput(inArg)

	inputText = string.lower(inArg)

	if inputText == 'hi' then outputText = 'Thanks for saying HI'
		elseif inputText == 'hello' then outputText = 'Thanks for saying HELLO'
		else outputText = 'Sorry I dont understand...'
	end

	SKIN:Bang('!SetOption', 'RESPONDINGTEXT', 'Text', outputText)
	SKIN:Bang('!UpdateMeter', 'RESPONDINGTEXT')
	SKIN:Bang('!Redraw')

end
GIF.gif
You do not have the required permissions to view the files attached to this post.
hashtaghashtag9967
Posts: 8
Joined: August 26th, 2017, 12:38 pm

Re: AI lua troubles

Post by hashtaghashtag9967 »

THANK YOU SO MUCH! it works now i will use it to take over the WORLD!!! MUWAHHAHHA!!!, or just have a cool desktop thing to show off at school(same thing) seriously tho thanks your awesome. :D
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AI lua troubles

Post by jsmorley »

hashtaghashtag9967 wrote:THANK YOU SO MUCH! it works now i will use it to take over the WORLD!!! MUWAHHAHHA!!!, or just have a cool desktop thing to show off at school(same thing) seriously tho thanks your awesome. :D
Glad to help. As I said above, I'm very impressed with how you jumped into this unafraid and with your hair on fire. Nice job. You got a few things wrong initially, but we were all new at this once, and you are well on your way. You will be the one giving advice soon.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AI lua troubles

Post by jsmorley »

One bit of advice I can give it to make use of the About / Log and About / Skins panels from the Rainmeter tray icon. In general, and with Lua in particular, that can give you a lot of help debugging.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: AI lua troubles

Post by jsmorley »

On last thing, NEVER set Update=10 on your skins. The lowest possible value for that is 16, and in any case, any skin that really needs Update=16, which is going to cause Rainmeter to use a lot of CPU, is a bad skin, poorly conceived or poorly designed. The only exception might be a complicated "visualizer" skin using the AudioLevel plugin, and it is my personal opinion that those are just a bad idea from the start...