Using an Expression as Index OR Appending Text to Expression Results


#1

1) Give a description of the problem
Without posting the whole mess here, I’m trying to generate some weather forecast slides with the daily High and Low temps in the Title. I’ve tried doing this with expressions and variables, but have run into some issues that I wonder are caused by syntax or just a ‘no, you can’t do that’.

First, I tried joining text after the result of an expression, but it doesn’t work:
arrayItem(ActiveIndex,Highs) + ‘text’ —> this only returns the variable and doesn’t append anything to it. Is there a way to append text and/or more expressions to this?

Second, I tried just pulling the results from the weather module, but it didn’t like math in the index. Is there a way to do this?
’:wu-v3-{$weather.forecast10day.forecast.simpleforecast.forecastday[ActiveIndex-1].icon}:’

In the above example, just using “ActiveIndex” works… it’s the math function that sends it out in the weeds. I’ve tried enclosing it in parentheses and curly brackets, but neither of those work either.

I can find workarounds to either one of these, but if there is a way to make these work, it’d streamline some of my pistons. Just trying to figure out if it’s a webCoRE limitation or a me limitation!

Thanks!


#2

You can’t do maths on a sting, try using:

concat(value1, value2, value3, valueN)

This will put a sentence together.

concat(arrayItem(ActiveIndex,Highs), text)


#3

In regards to ActiveIndex-1… what is ActiveIndex? A custom variable?

If so, do the maths in a second variable and reference that in the square brackets instead, you can’t do any maths in the $weather square brackets directly.


#4

Thanks Robin! I tried concat($weather string, ‘text’) and still only saw the weather string as the result. That’s when I was at a total loss and decided to post here.

Yeah, ActiveIndex is just a variable I use that gets increased through each pass of the loop… I needed to do the math in there because I was trying to use one variable for the Tile Number (starts at 1) and the Index (starts at zero).

The following gives me the high temp beyond the colon in the $weather variable ‘fahrenheit: 63’

And this still returns the same?

So I took it down to basics…

Then added concat…

and it worked.

What I can’t figure out is, what is it about my first expression that makes it not play nicely with appending text?


#5

Use the system variable $index, it does the counting for you.

If you’re using a loop, you can tell it to start at 1

I’ll tinker with concat… should work??!

Can you post your piston as well… helps me see what you’re trying to do.


#6

Have you seen this:

https://wiki.webcore.co/Samples#Weather_Tiles


#7

I don’t get the usage of mid in your first example???

Syntax:

mid("Hello World", 1) = ello World

But you’ve effective done:

mid("Hello World"+1) = wont work


#8

I’ve seen the samples, but I’m trying to use this as a learning experience of what I can do or can’t do in here… as a HW engineer by (OLD) background, I can only learn this stuff by doing, lol.

The +1 was for the “Index of” function… if I didn’t have the “+1” then ‘mid’ would return the : in the result… index of was basically looking for the : in “fahrenheit:63” and taking only the characters after it. I was going to do a static offset, but then when the preceding celcius temperature changed from 1 to 2 digits, it’d break my expression.

I kept playing with it…and got rid of my local variable and put the $weather variable directly into my expression. This gets my what I was after, but I still can’t append any text to it using + or concat… any thoughts why?

Thanks again for your help!


#9

can you post that expression as raw text please so I can tinker… saves me typing it


#10

Of course!
mid($weather.forecast10day.forecast.simpleforecast.forecastday.high[ActiveIndex],lastindexOf($weather.forecast10day.forecast.simpleforecast.forecastday.high[ActiveIndex],’:’)+1)

I’ve tried inserting String, thinking it was an integer and rebuffing + text but that didn’t work either. Similarly, adding +5 to the outside of it changed nothing… result was still 66.


#11

what value have you got in activeindex?


#12

1


#13

$weather.forecast10day.forecast.simpleforecast.forecastday.high[1].fahrenheit

gives same result


#14

Ugh, I completely missed this resonse earlier, sorry! I never noticed the $index variable.

Here is the piston:


#15

and try this:

$weather.forecast10day.forecast.simpleforecast.forecastday.high[1].fahrenheit " appended text"


#16

You know, I saw that at one point and it didn’t even register… I had it in my head that I’d have to use the same indexOf blah blah blah as when I intially pulled the 10-day forecast into a variable and tried to pick it apart:
[[celsius:20, fahrenheit:68], [celsius:21, fahrenheit:69], [celsius:22, fahrenheit:71], [celsius:23, fahrenheit:74], [celsius:24, fahrenheit:76], [celsius:24, fahrenheit:75], [celsius:24, fahrenheit:76], [celsius:25, fahrenheit:77], [celsius:23, fahrenheit:74], [celsius:24, fahrenheit:75]]

So really all I needed to do was the math in that expression, ActiveIndex+1 or similar, but now understand that’s not possible.

In other words, I got all wrapped up trying to make the first solution work, then tried to make the expression using the $weather variable as complicated as it was for my local variable… and successfully made it complicated AND broken!

Thank you for the sanity check!! I would have kept looking right past it.

Cheers,
-Dan


#17

This might help:


#18

Perfect timing, I was just trying to figure out the $index variably by using a Log to Console command… it’s null if I use it in an expression and I couldn’t figure out how to set it to a starting value.

Thanks again, that helps immensely!