the code is directly from the sample code collection.
see C:\Program Files (x86)\Corona Labs\Corona SDK\Sample Code\Storage\SaveTable
the code is directly from the sample code collection.
see C:\Program Files (x86)\Corona Labs\Corona SDK\Sample Code\Storage\SaveTable
What version of Corona SDK are you using?
I just checked on my Mac with 2929 and it’s there.
Here is the source code for it:
-- This adds string "split" functionality similar to "explode()" in PHP local M = {} M.split = function( str, pat ) local t = {} local fpat = "(.-)" .. pat local last\_end = 1 local s, e, cap = str:find( fpat, 1 ) while s do if ( s ~= 1 or cap ~= "" ) then table.insert( t, cap ) end last\_end = e + 1 s, e, cap = str:find( fpat, last\_end ) end if ( last\_end \<= #str ) then cap = str:sub( last\_end ) table.insert( t, cap ) end return t end return M
2016.2830 simulator version (“about similator”)
win 8.1 64bit
I copied code from the tablesave sample.
2830 is a couple of public builds old now. 2906 is the current public build and daily builds are up to 2932. You might want to consider updating your Corona SDK. I just checked on 2932 and str.lua is in the folder on Windows.
Rob
https://docs.coronalabs.com/daily/api/
1 - ‘str’ not shown in docs & no string.split() either.
2 - are you sure this is part of the build or a customization?
3 - note that the sample file savetable was delivered w/ the version I have running
showing the “str.split()” fcn.
I’m going to update my version anyway. Not sure if daily or public yet.
Thank you much for the information, etc.
Str and string.split are not build in APIs.
For string.split see
https://coronalabs.com/blog/2013/04/16/lua-string-magic/
“str” is not a standard API library. string.* is. However the a bunch of other “string manipulation” functions that are not part of the Lua standard string.* library that lots of people like to use. As a developer you would create a lua file in your project and in that file you can add your own library of functions, even adding them to the string.* name space for you app. string.split (or as the savetable sample uses it: str.split more on that in a bit).
If you want a split function you have to add it yourself. That means either writing your own or finding on on the internet or having a developer help you out. You can include it in your code where you need it, or you can make your own “string” module … just don’t name it “string”. This is what the sample app you’re looking at does.
It has a file called str.lua in the folder. It simply has a string.split function in it and in the way that sample app is working you end up calling “str.split()”. In my case I have an “extras.lua” or “utility.lua” file that I put random useful functions in. But I use an appropriate name space for several of the functions. For instance I don’t call “utility.split()”, I have it so I add the split function to the string namepsace and do string.split().
Rob
You should try to read documentation
1)https://docs.coronalabs.com/api/library/native/newTextField.html
2)https://docs.coronalabs.com/daily/guide/data/readWriteFiles/index.html
3)https://docs.coronalabs.com/api/library/display/newText.html
I always thought I could get away with not reading, but it is important tool you have to master.
Thanks for the suggestions. Unfortunately, I have already looked at the links you show. The info falls short. It is not clear how to get a text input and do something w/ it. Yes, I am new to LUA. This issue has been under investigation for many many days.
I much appreciate all of your help.
Ed made this sample a while back when I was having trouble with text boxes which maybe of some help
Edit: forgot link
https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2016/04/native_textbox
Thank you. I have been thru all of the videos, tutorials, etc. at “learn lua”. See post re: confusion w/ unclear “examples”.
Believe me, I have been thru ALL of the available education at learn lua & looked at many commands, but still not clear in accepting input from a text box & printing it or saving it to a file (basically, I am unclear how a quantity from a text input box is captured and then processed (stored, printed, etc.). How does the text box know when user has finished input and stores into a variable. On a PC, there is a return or a button to execute the capture. Not that way on phones.
I appreciate all of your help and suggestions. I will check the example you linked. I will revisit the “learn lua” again.
I mistakenly thought “learn lua” was the menu under “learn” on the main page. Thanks again.
I will try to break down text boxes and text field the best I can. First they are native which means they will alway be on top of any thing else (expected for other native things). Other than that they really operate like other display objects. They can be inserted into groups, you can use display.remove() to delete them. Thier are some exceptions Windows text box backgrounds can not be removed, basically what you see is what you get on Windows. Also Windows phone does not have native elements. You can add event listeners which basically like corona tell you, yo something changed and you can do what you will with it. Event listeners are only activate when something is changed or updated. In order to get text from a box or field you would call .text
for example if you have a text field called myTextFeild
print(myTextFeild.text)
This would give you text input you want. But if you read the examples in the documentation above it will show how to take advantage of event listeners( it is link 1)
as for the return button, I don’t know what you are talking about but iPhones and most android phones (that I know of) have some form of return button, it could say go, enter, or search. As for how you would get this input the text listener event.phase == “submitted”. If user click anywhere but your text box or field it should return event.phase == “ended”
THANKS!!!
That was very informative. I think I understand the mechanics better now. I will continue to look over the info you provided.
I was talking about the <return> on the PC keyboard.
MUch appreciated.
The return key is handled as “submitted” event.phase for boxes and fields for pcs
OK. thx.
Our business app sample (https://github.com/coronalabs-samples/business-app-sample) has a page that shows how to read data from an SQLite database, populate a tableView. Tap on one of the items and go to a form that lets you edit the data and save it and has a button to add new records.
It’s a great resource on how to figure out how to do text field work in Corona. Also don’t forget to look in our sample code that ships with the product. Its in your CoronaSDK/SampleCode/Interface folder.
Rob
this is part of my code; I get this below; any ideas?
" userName1 = " {_class = {__index = nil, addEventListener = function() --[[…skipped…]] end, removeEventListener …
addEventListener: listener cannot be nil: nil
stack traceback:
[C]: in function ‘error’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
?: in function ‘addEventListener’
F:\app00000006a\MPGcalcA\main.lua:44: in main chunk
------------- code
local userName1 = native.newTextField(360,-85.33333333333328,690,34.13333333333333)
print( " userName1 = ", userName1 )
– local userName1 = native.newTextField( dispCentX, ( dispTop - ( spaceInputFieldY * posuserName1Y ) ), ( dispWd - 30 ), sizeInputFieldY )
userName1:addEventListener( “userInput”, readSnapData )
where is your readSnapData function?