Page 1 of 1
Can't seem to get Python to write to a variable
Posted:
Fri Oct 14, 2022 7:48 am
by rainman50
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.
Re: Can't seem to get Python to write to a variable
Posted:
Fri Oct 14, 2022 8:47 am
by FlyingDiver
Post the entire script using the CODE tags so we can see what line 11 is.
Re: Can't seem to get Python to write to a variable
Posted:
Fri Oct 14, 2022 11:26 am
by rainman50
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
Re: Can't seem to get Python to write to a variable
Posted:
Fri Oct 14, 2022 11:27 am
by FlyingDiver
Please use CODE tags.
Re: Can't seem to get Python to write to a variable
Posted:
Fri Oct 14, 2022 11:33 am
by rainman50
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)
Re: Can't seem to get Python to write to a variable
Posted:
Fri Oct 14, 2022 11:36 am
by rainman50
I'm new to this I'll have to lookup code tags....
Re: Can't seem to get Python to write to a variable
Posted:
Fri Oct 14, 2022 11:38 am
by rainman50
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.
Re: Can't seem to get Python to write to a variable
Posted:
Fri Oct 14, 2022 11:46 am
by FlyingDiver
It's the forum software. Look above the text input field. Select the code lines then press the "Code" button above.
Re: Can't seem to get Python to write to a variable
Posted:
Fri Oct 14, 2022 11:48 am
by FlyingDiver
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".
Re: Can't seem to get Python to write to a variable
Posted:
Fri Oct 14, 2022 12:31 pm
by rainman50
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.
Re: Can't seem to get Python to write to a variable
Posted:
Sat Oct 15, 2022 1:11 pm
by DaveL17
Bringing over from
https://forums.indigodomo.com/viewtopic.php?f=82&t=26615#p214111Your 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.
Re: Can't seem to get Python to write to a variable
Posted:
Sat Oct 15, 2022 5:59 pm
by rainman50
Thank you very much, DaveL17
I sure have a lot to learn.
Re: Can't seem to get Python to write to a variable
Posted:
Sat Oct 15, 2022 6:03 pm
by DaveL17
Not a problem. None of us were born knowing Python.