# Copy of script not working anymore

**URL:** <https://community.homey.app/t/copy-of-script-not-working-anymore/124009>\
**Category:** Questions & Help\
**Tags:** homeyscript\
**Created:** [December 14, 2024, 1:40pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009 "2024-12-14T13:40:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheKos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/thekos/32/33969_2.png) [@TheKos](https://community.homey.app/u/TheKos)\
**Post date:** [December 14, 2024, 1:40pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/1 "2024-12-14T13:40:51Z")

</div>

I have a simple script to reset some variables.  
Since shortly I get the message “Classic”, meaning I seem to use an old API library or something  
When I copy and past the script to a script with a new name, but same content, it does not work anymore. I can’t figure out what’s wrong. Debugging results in that it suddenly cannot find await Homey.logic.getVariables anymore by its name, it returns “undefined”. In the original version the exact same code returns the correct values. So apparently I need to use convert my code, but no idea, read the tutorial, but could not find the solution.

My simple code

setparvalue(“testvar”,“test”);  
setparvalue(“testvar1”,“test”);  
setparvalue(“testvar2”,“test”);

//

async function setparvalue(varname, varvalue)  
{  
**const advancedvar = await Homey.logic.getVariables(({filter: { name: varname }}));**  
const parval=Object.values(advancedvar)[0].value  
const parvalid=Object.values(advancedvar)[0].id

log(parval,parvalid)  
await Homey.logic.updateVariable({id: parvalid, variable: {value: varvalue}})  
}

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [December 14, 2024, 2:08pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/2 "2024-12-14T14:08:50Z")

</div>

I am not a Homey programmer, but maybe this helps: [HomeyAPI - Homey Web API](https://athombv.github.io/node-homey-api/HomeyAPI.html)

---

<div class="post-metadata">

**Author:** ![TheKos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/thekos/32/33969_2.png) [@TheKos](https://community.homey.app/u/TheKos)\
**Post date:** [December 14, 2024, 2:35pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/3 "2024-12-14T14:35:32Z")

</div>

Could be, but I usually like some coding examples. I often use the examplexys.js that are in my homey scripting evironment. But also these examples all have a orange flag, probably because of being classic. So a bunch of new examples in the scripting environement would also be helpful.  
This tutorial does not help very much either. [Tutorial: Migrating deprecated scripts - HomeyScript](https://athombv.github.io/com.athom.homeyscript/tutorial-migrate.html)

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [December 14, 2024, 3:41pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/4 "2024-12-14T15:41:37Z")

</div>

I got a different error

```auto

setparvalue("testvar","test");
setparvalue("testvar1","test");
setparvalue("testvar2","test");

//

async function setparvalue(varname, varvalue)
{
const advancedvar = await Homey.logic.getVariables(({filter: { name: varname }}));
const parval=Object.values(advancedvar)[0].value
const parvalid=Object.values(advancedvar)[0].id

log(parval,parvalid)
await Homey.logic.updateVariable({id: parvalid, variable: {value: varvalue}})
}

```

```auto

"root":{1 item
"error":string"Can't find variable: log"
}

```

---

<div class="post-metadata">

**Author:** ![Arnt\_Soloy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arnt_soloy/32/58318_2.png) [@Arnt\_Soloy](https://community.homey.app/u/Arnt_Soloy)\
**Post date:** [December 14, 2024, 4:03pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/5 "2024-12-14T16:03:49Z")

</div>

You may try use " instead of “

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 14, 2024, 4:24pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/6 "2024-12-14T16:24:33Z")

</div>

> [@TheKos](#):
>
> Debugging results in that it suddenly cannot find await Homey.logic.getVariables anymore by its name, it returns “undefined”.

So if you run this code:

```auto
console.log(Homey.logic.getVariables);

```

It logs `undefined`?

---

<div class="post-metadata">

**Author:** ![TheKos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/thekos/32/33969_2.png) [@TheKos](https://community.homey.app/u/TheKos)\
**Post date:** [December 14, 2024, 5:30pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/7 "2024-12-14T17:30:43Z")

</div>

The code + result in the existing old code

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/9/49586bc933b4c2e0ac6594e3447c27890efb526c.png)  
Pasted this in a new script, and it does not work anymore, does not find the correct variable, 3 time the same id. which is not correct. In the old code the correct id’s are found.  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/a/8a15a351db62d79b0d22fb12da6c4efa9358e1fd.png)

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [December 14, 2024, 5:37pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/8 "2024-12-14T17:37:05Z")

</div>

To answer [Robert’s Q](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/6):

> ![1000038834](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/b/4bfd6d6f3f95d2b8cde74d33bfa712e3304223ee.jpeg)

When ran as edited ‘classic’ script, _other result_:

> ![1000038836](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/2/22faa01ac1032a22f0f34590af88d846c40bdd87.jpeg)

---

<div class="post-metadata">

**Author:** ![s73nm](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/s73nm/32/110438_2.png) [@s73nm](https://community.homey.app/u/s73nm)\
**Post date:** [December 14, 2024, 6:07pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/9 "2024-12-14T18:07:56Z")

</div>

I’m not a developer, so apologies if this is besides the point, but aren’t you missing semicolons at the end of lines 13, 14, 15 and 18?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 14, 2024, 6:30pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/10 "2024-12-14T18:30:27Z")

</div>

No.

If that (or incorrect quotes, as was suggested earlier) was of relevance, the script would stop with a syntax error, and it doesn’t.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 14, 2024, 6:31pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/11 "2024-12-14T18:31:53Z")

</div>

“Script Success” 🤷🏼‍♂️

It says “Returned: undefined” because the script doesn’t return anything.

It’s unclear to me what the actual problem is here.

---

<div class="post-metadata">

**Author:** ![TheKos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/thekos/32/33969_2.png) [@TheKos](https://community.homey.app/u/TheKos)\
**Post date:** [December 14, 2024, 8:12pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/12 "2024-12-14T20:12:36Z")

</div>

The problem to me is that I have an old script that I use as an example for new scripts, but in the new script exactly the same code does not work. The old script is since shortly indicated as “classic” , with the suggestion to migrate it to something else. Also this is left to the programmer to find out for him/herself, because to me the manual offered is abacadabra, I need examples. It would be helpful if there was a kind of indication what pieces of code need attention, or even an upgrade service, should be possible in these days of AI.

Anyway, I tried some different code I found in a post, and that works, but I have a bunch of scripts with the “classic” indication so I would rather not spent a day per script migrating it to the new HomeyScript version. I will post a message to the Homey support team.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/1/315b583af19051cfa5343b5ec0bd5aacfe63ef12.png)

---

<div class="post-metadata">

**Author:** ![Arnt\_Soloy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arnt_soloy/32/58318_2.png) [@Arnt\_Soloy](https://community.homey.app/u/Arnt_Soloy)\
**Post date:** [December 14, 2024, 8:26pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/13 "2024-12-14T20:26:29Z")

</div>

I know the frustation on finding updated examples etc… been there myself… this script example will do what you want i belive, there is a slight difference from your orginal code:

```auto
setparvalue("testvar","test");
setparvalue("testvar1","test");
setparvalue("testvar2","test");

//

async function setparvalue(varname, varvalue) {
  const advancedvar = await Homey.logic.getVariables({ filter: { name: varname } });
  
  // Find the variable object by its name
  const variable = Object.values(advancedvar).find(v => v.name === varname);

  if (!variable) {
    throw new Error(`Variable ${varname} not found.`);
  }

  const parval = variable.value;
  const parvalid = variable.id;

  log(parval, parvalid);
  
  await Homey.logic.updateVariable({ id: parvalid, variable: { value: varvalue } });
}

```

tested and working with changing the variables.  
i claim no expertise in coding, this was done with GPT O1

and it seem log wil return undefined no matter… might be a Homey thing…

---

<div class="post-metadata">

**Author:** ![TheKos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/thekos/32/33969_2.png) [@TheKos](https://community.homey.app/u/TheKos)\
**Post date:** [December 14, 2024, 8:33pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/14 "2024-12-14T20:33:14Z")

</div>

Thanks, I also tried AI through Gemini, but that came up with non working code, so you are better at AI prompting than me.

---

<div class="post-metadata">

**Author:** ![Arnt\_Soloy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arnt_soloy/32/58318_2.png) [@Arnt\_Soloy](https://community.homey.app/u/Arnt_Soloy)\
**Post date:** [December 14, 2024, 8:39pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/15 "2024-12-14T20:39:05Z")

</div>

Well, i should try be better reading full posts before posting myself… Well done on finding the solution yourself 🙂

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [December 14, 2024, 9:10pm UTC](https://community.homey.app/t/copy-of-script-not-working-anymore/124009/16 "2024-12-14T21:10:55Z")

</div>

@TheKos I see more changes in your code. So I am curious to know if you have any idea what has changed? Is it the library or the script language version? Or are you merely following examples?
