Can't seem to get Python to write to a variable

Posted on
Fri Oct 14, 2022 7:48 am
rainman50 offline
Posts: 295
Joined: Feb 13, 2006
Location: Michigan

Can't seem to get Python to write to a variable

I have been using Indigo 7.3 for quite sometime since Applescript was removed from the software. I want to upgrade to 2022.1 software.
I tried this in Indigo 7.3 and the new Indigo 2022.1.

So I'm converting Apple script to Python. I'm having a problem writing to a variable and making the "If statement" work. I have looked at others software using Python and cant seem to make it work without errors.

here is an example with trying to put 7 into a variable.

Just to show that I have the correct variable reference number:
indigo.variables[489801056] # "HumidityTempDiffGarageNorth"

test = 7
indigo.variable.updateValue(489801056, test)


This is the error that comes back in the event log.


Script Error embedded script: 'instancemethod' object has no attribute '__getitem__'
Script Error Exception Traceback (most recent call shown last):

embedded script, line 11, at top level
TypeError: 'instancemethod' object has no attribute '__getitem__'


I have tried also brackets [489801056, test] instead of (489801056, test) but both fail.

Posted on
Fri Oct 14, 2022 8:47 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Can't seem to get Python to write to a variable

Post the entire script using the CODE tags so we can see what line 11 is.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Oct 14, 2022 11:26 am
rainman50 offline
Posts: 295
Joined: Feb 13, 2006
Location: Michigan

Re: Can't seem to get Python to write to a variable

Sorry . The reset is pretty much comments. here: I think line 11 is the line in question.


#HumidityOutsideTemp = indigo.variables[1949392360]
#HumidityTangentTempGarage = indigo.variables[504168221]
#HumidityTempDiffGarageNorth = indigo.variables[489801056]
#
#
#indigo.variable.updateValue[489801056, test] # HumidityTempDiffGarageNorth


#indigo.variables[489801056] # "HumidityTempDiffGarageNorth"
test = 7
indigo.variable.updateValue(489801056, 6)
#
#
#if HumidityOutsideTemp > HumidityTangentTempGarage:
#HumidityTempDiffGarageNorth = 0
#indigo.variable.updateValue(489801056, 7)

#else:
# HumidityTempDiffGarageNorth = ((HumidityTangentTempGarage - HumidityOutsideTemp) / 3)
# indigo.variable.updateValue(504168221, HumidityTempDiffGarageNorth)
end

Posted on
Fri Oct 14, 2022 11:27 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Can't seem to get Python to write to a variable

Please use CODE tags.
Attachments
Screen Shot 2022-10-14 at 1.27.30 PM.png
Screen Shot 2022-10-14 at 1.27.30 PM.png (7.63 KiB) Viewed 1890 times

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Oct 14, 2022 11:33 am
rainman50 offline
Posts: 295
Joined: Feb 13, 2006
Location: Michigan

Re: Can't seem to get Python to write to a variable

in the one I gave you had a 6 being stored instead of "test". But neither one works.

heres the error script one with test instead of 6.


#HumidityOutsideTemp = indigo.variables[1949392360]
#HumidityTangentTempGarage = indigo.variables[504168221]
#HumidityTempDiffGarageNorth = indigo.variables[489801056]
#
#
#indigo.variable.updateValue[489801056, test] # HumidityTempDiffGarageNorth


#indigo.variables[489801056] # "HumidityTempDiffGarageNorth"
test = 7
indigo.variable.updateValue(489801056, test)
#
#
#if HumidityOutsideTemp > HumidityTangentTempGarage:
#HumidityTempDiffGarageNorth = 0
#indigo.variable.updateValue(489801056, 7)

#else:
# HumidityTempDiffGarageNorth = ((HumidityTangentTempGarage - HumidityOutsideTemp) / 3)
# indigo.variable.updateValue(504168221, HumidityTempDiffGarageNorth)
end

heres the error script one with test instead of 6.


Script Error embedded script: Python argument types in
VariableCmds.updateValue(VariableCmds, int, int)
did not match C++ signature:
updateValue(_VariableCmds {lvalue}, boost::python::api::object elem, CCString value)
Script Error Exception Traceback (most recent call shown last):

embedded script, line 11, at top level
ArgumentError: Python argument types in
VariableCmds.updateValue(VariableCmds, int, int)
did not match C++ signature:
updateValue(_VariableCmds {lvalue}, boost::python::api::object elem, CCString value)

Posted on
Fri Oct 14, 2022 11:36 am
rainman50 offline
Posts: 295
Joined: Feb 13, 2006
Location: Michigan

Re: Can't seem to get Python to write to a variable

I'm new to this I'll have to lookup code tags....

Posted on
Fri Oct 14, 2022 11:38 am
rainman50 offline
Posts: 295
Joined: Feb 13, 2006
Location: Michigan

Re: Can't seem to get Python to write to a variable

Sorry about my newbee status. I greatly appreciate your help. I'll have to look into code tags.
I'll get back when I know a little more of Python.

Posted on
Fri Oct 14, 2022 11:46 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Can't seem to get Python to write to a variable

It's the forum software. Look above the text input field. Select the code lines then press the "Code" button above.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Oct 14, 2022 11:48 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Can't seem to get Python to write to a variable

I think the problem is you're trying to write an integer to the variable. You need to be using a string. Like "6" or "7" or "test".

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Oct 14, 2022 12:31 pm
rainman50 offline
Posts: 295
Joined: Feb 13, 2006
Location: Michigan

Re: Can't seem to get Python to write to a variable

Thank you Flying Diver.

I see what you are talking about now. Integers. floats and strings. Have to make sure I treat them as such.

Much Appreciated.

Posted on
Sat Oct 15, 2022 1:11 pm
DaveL17 offline
User avatar
Posts: 6757
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Can't seem to get Python to write to a variable

Bringing over from https://forums.indigodomo.com/viewtopic.php?f=82&t=26615#p214111

Your code here:
Code: Select all
test = indigo.variables[240228976] # "HumidityOutsideTemp"]
indigo.variable.updateValue("HumidityTempDiffGarageNorth", str(test))
Is doing what it should, but not what you want. The reason is in the first line, you are actually asking for a copy of the variable object instead of the variable object's value. If you want the value stored in the variable, you have to do this (note the first line):
Code: Select all
test = indigo.variables[240228976].value # "HumidityOutsideTemp"]
indigo.variable.updateValue("HumidityTempDiffGarageNorth", str(test))
Take a look at this page which shows some examples.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Oct 15, 2022 5:59 pm
rainman50 offline
Posts: 295
Joined: Feb 13, 2006
Location: Michigan

Re: Can't seem to get Python to write to a variable

Thank you very much, DaveL17

I sure have a lot to learn.

Posted on
Sat Oct 15, 2022 6:03 pm
DaveL17 offline
User avatar
Posts: 6757
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Can't seem to get Python to write to a variable

Not a problem. None of us were born knowing Python. :D

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests