Getting into LiveCode for iOS? Ask your questions here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
Kaubs
- Posts: 124
- Joined: Wed Jun 29, 2011 3:55 am
Post
by Kaubs » Fri Jul 22, 2011 6:35 pm
So! I am so close to finishing my app I can almost taste it. I greatly appreciate the help that everyone has given thus far. The last part of my app is a photo gallery. I have it about 99% of the way functional however I think I know what is causing my last issue.
First here is the code.
Code: Select all
on opencard
post "ping" to url ("##ahiddenurl")
put it into tvar1
replace "|" with return in tvar1
put line 1 of tvar1 into data1
put line 2 of tvar1 into data2
put line 3 of tvar1 into data3
put line 4 of tvar1 into data4
put line 5 of tvar1 into data5
put line 6 of tvar1 into data6
put line 7 of tvar1 into data7
put line 8 of tvar1 into data8
put line 9 of tvar1 into data9
set the filename of image "image1" to data1
set the filename of image "image2" to data2
set the filename of image "image3" to data3
set the filename of image "image4" to data4
set the filename of image "image5" to data5
set the filename of image "image6" to data6
set the filename of image "image7" to data7
set the filename of image "image8" to data8
set the filename of image "image9" to data9
end opencard
So here is the problem. I've removed my URL from the first line for various reasons. All of the photo's show up in my gallery except for image1. I think the issue is that data 1 contains a space and then the url....all of the other data2-9 work just fine but dont contain that space....is there a way to specify like -1 space when importing the data with the line "put line 1 of tvar1 into data1". Im almost positive this will fix the issue I am having. Thanks!!!!!
-
SparkOut
- Posts: 2943
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Fri Jul 22, 2011 7:45 pm
I would change all those longhand lines of code so that you can do a loop to populate the image filenames. If you use "split" you can change the variable into an array, according to which character you use as a delimiter and in this case you can simply turn the variable into an array which (with only the one delimiter specified) will produce an array with numbered keys.
Code: Select all
put " moo| cow|blue|cake| fish| wombat|larder|eight| Monster" into tData
-- ok so these words will not work to be a filename for the images, but you get the idea.
split tData by "|"
repeat with i = 1 to 9
repeat while tData[i] begins with space
delete char 1 of tData[i]
end repeat
set the filename of image ("image" & i) to tData[i]
end repeat
If you have a problem with the filename beginning with a single (or potentially more) spaces then you can use the above to delete any leading spaces. If you need to remove all spaces in the filename then you can forget about the inner repeat loop and do something like:
Code: Select all
put " moo| cow|blue|cake| fish| wombat|larder|eight| Monster" into tData
-- ok so these words will not work to be a filename for the images, but you get the idea.
split tData by "|"
repeat with i = 1 to 9
replace space with empty in tData[i]
-- or replace space with "+" or "%20" or whatever is appropriate
set the filename of image ("image" & i) to tData[i]
end repeat
You could also strip any leading and trailing spaces in the filename by
Code: Select all
put word 1 to -1 of tData[i] into tData[i]
Hope that helps
-
Kaubs
- Posts: 124
- Joined: Wed Jun 29, 2011 3:55 am
Post
by Kaubs » Fri Jul 22, 2011 8:46 pm
Sparkout,
That is amazing. It's exactly what I would like to do in a much simpler format. I do have a question with this line however.
"set the filename of image ("image" & i) to tData"
I dont quite understand how it works. If you have a little time would you mind breaking it down for me? I cannot seem to apply this to my images. The array seems to work perfectly as I've simply answered tdata but the line I quoted doesn't seem to populate source data for the images.
Thanks!
-
Kaubs
- Posts: 124
- Joined: Wed Jun 29, 2011 3:55 am
Post
by Kaubs » Fri Jul 22, 2011 9:31 pm
Seems almost like it wants to populate each image with the URL 9 times now but I'm not positive.
-
SparkOut
- Posts: 2943
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Fri Jul 22, 2011 10:24 pm
repeat with i = 1 to 9 should loop 9 times with i being the value 1 through 9 in each case
the parentheses round the "quoted literal" plus variable should force the engine to parse the contents of the parentheses in each case.
So for the first iteration when i = 1 the line should be the equivalent of:
set the filename of image "image1" to tData[1]
when next time around it should be
set the filename of image "image2" to tData[2]
and so on. ("image" & i) will be parsed in each case to be the name "image" with the current value of i appended.
I don't know what the source data contains but in theory this should take each element 1 through 9 of the array tData and apply the contents as the filename for each image named "image1" through "image9"
I hope that clears things up - if not, then please just say, and we can try to get to the bottom of it.
-
Kaubs
- Posts: 124
- Joined: Wed Jun 29, 2011 3:55 am
Post
by Kaubs » Mon Jul 25, 2011 4:53 pm
Thanks sparkout! That makes a lot more sense. I was trying to apply the data using tdata I think and in my head it made no sense. This I understand much more. Ill give it a go!