Sports Text Manager Game (Wrestling)...

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

kap1987
Posts: 21
Joined: Tue Feb 21, 2017 6:25 pm

Re: Sports Text Manager Game (Wrestling)...

Post by kap1987 » Thu Mar 30, 2017 1:36 pm

I mean image, as mentioned i tried both... but even the example script in my quote doesn´t work...
on mouseUp
put revOpenDatabase("sqlite", "C:\Users\kap19\OneDrive\EWR App\Neuer Ordner\runrevemails.sqlite", , , , ) into tID
put revQueryDatabase(tID, "SELECT * FROM images WHERE id=" & field "id" & ";") into tRecordSet
put revDatabaseColumnNamed(tRecordSet, "image", tImage) into tError #tImage contains data, tError contains errors
set the text of image "imagecontainer" to tImage
revCloseCursor tRecordSet
revCloseDatabase tID
end mouseUp
There was a link to an external database at "put revOpenDatabase..." But i was not able to open this database alone in another application like sqlite admin to see if it is stored different than i did. I changed teh path to the url of my database as you can see in the quote. The original example works perfect. But my example doens´t :(
Livecode has an Runtime error when clicking the button to load the image into the imagecontainer.

The original example was this: http://forums.livecode.com/phpBB2/downl ... hp?id=6789

Klaus
Posts: 9698
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Sports Text Manager Game (Wrestling)...

Post by Klaus » Thu Mar 30, 2017 2:08 pm

Hi Kap,

hm, I think we first need to figure out in what format the images are stored in the database.
Can you write the image to your hd and open it with a text editor?
Maybe the headers of the file will give us any hints:

Code: Select all

...
put revDatabaseColumnNamed(tRecordSet, "image", tImage) into tError

## Important, always check for possible errors:
if tError begins with "revdberr" then
   answer "An error occurred!" & CR & tError
   exit to top
end if
put tError into url("binfile:" & (specialfolderpath("desktop") & "/testimage.jpg"))
## or .png, if it is an PNG image. 
## Or leave out the suffix if you are not sure.
...
Then post the first 10 characters of that file here.

Best

Klaus

P.S.
"Neuer Ordner"? Are you tscherman (or a schwyzer)? :D

kap1987
Posts: 21
Joined: Tue Feb 21, 2017 6:25 pm

Re: Sports Text Manager Game (Wrestling)...

Post by kap1987 » Thu Mar 30, 2017 2:14 pm

Yes i´m from good old germany ;)

the first 10 characters of the image in text editor say: ÿØÿà JFIF

It is a jpg-file which is stored on my hd.


PS: i inserted your script...
error says: revdberr, invalid column name

the link i posted before was wrong... the original example is here to find: http://jasminedavid.on-rev.com/dbimage.livecode :mrgreen:

Klaus
Posts: 9698
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Sports Text Manager Game (Wrestling)...

Post by Klaus » Thu Mar 30, 2017 3:48 pm

Hi Kap,
kap1987 wrote:Yes i´m from good old germany ;)
das deuchte mich! :D
kap1987 wrote:the first 10 characters of the image in text editor say: ÿØÿà JFIF
It is a jpg-file which is stored on my hd.
Yep, a jpeg file, but is it "freshly" saved from the database?
Or is this the original file that you later stored in your db?
kap1987 wrote:PS: i inserted your script...
error says: revdberr, invalid column name
Aha,m so please check your SQL for the correct database column name!
kap1987 wrote:the link i posted before was wrong... the original example is here to find: http://jasminedavid.on-rev.com/dbimage.livecode :mrgreen:
The stack works as exspected here!


Best

Klaus

P.S.
There is also a new german Livecode forum here:
http://www.livecode-blog.de/forums/foru ... ode-forum/

kap1987
Posts: 21
Joined: Tue Feb 21, 2017 6:25 pm

Re: Sports Text Manager Game (Wrestling)...

Post by kap1987 » Thu Mar 30, 2017 4:17 pm

Yep, a jpeg file, but is it "freshly" saved from the database?
Or is this the original file that you later stored in your db?
what do you mean by "freshly" saved "from" the database. the jpeg is an old picture on my hd. it had nothing to do with livecode before. i just saved it "into" the database via sqlite admin.
Aha,m so please check your SQL for the correct database column name!
that´s the strangest thing of all...

for testing (like in the example - working - stack) i built a new table via sqlite admin in my database and called the table images". --> two columns "id" and "image"

then i used sqlite admin to store the image into the database. i opened the database in sqlite admin and edited the data. there is a view of the whole datagrid. with the two columns. when opening the symbol in the column "image" i was able to choose a picture which is stored on my hd. when changes where saved the picture was shown in the column "image" of id "1".


do i have to save it from livecode to database instead of via sqlite admin? if so - how?
it did nothing more to or with the image. ;)

Klaus
Posts: 9698
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Sports Text Manager Game (Wrestling)...

Post by Klaus » Thu Mar 30, 2017 9:44 pm

Hi kap,
kap1987 wrote:
Yep, a jpeg file, but is it "freshly" saved from the database?
Or is this the original file that you later stored in your db?
what do you mean by "freshly" saved "from" the database. the jpeg is an old picture on my hd. it had nothing to do with livecode before. i just saved it "into" the database via sqlite admin.
I meant if that was the image that you pulled out of the database and NOT the original file.
But since there was an error in your query this "hat sich erledigt"! :D
kap1987 wrote:
Aha,m so please check your SQL for the correct database column name!
that´s the strangest thing of all...
for testing (like in the example - working - stack) i built a new table via sqlite admin in my database and called the table images". --> two columns "id" and "image"

then i used sqlite admin to store the image into the database. i opened the database in sqlite admin and edited the data. there is a view of the whole datagrid. with the two columns. when opening the symbol in the column "image" i was able to choose a picture which is stored on my hd. when changes where saved the picture was shown in the column "image" of id "1".
Hm, sorry, no more brilliant ideas here in the moment...
kap1987 wrote:do i have to save it from livecode to database instead of via sqlite admin? if so - how?
it did nothing more to or with the image. ;)
Since it actually works, as shown in your example stack you posted, no need to use LC for this.

But basically you "base64encode" the binary image file -> url("binfile:path/to/image.jpg")
and then store the data as BLOB in the db. I never had to to this but I think then you need
to add "'*b" to the variable holding your binary data.

Check the dictionary for "revdb_execute" there is an example for this.


Best

Klaus

kap1987
Posts: 21
Joined: Tue Feb 21, 2017 6:25 pm

Re: Sports Text Manager Game (Wrestling)...

Post by kap1987 » Sat Apr 01, 2017 10:07 am

i think there might be a problem with the encoding/decoding of the image data inside the sqlite database or on the way to show it in livecode or the app.

is there an easy way to store many pictures at the same time in the database with livecode because i think the problem is when storing them inside the database via sqlite admin (perhaps here is the encoding/decoding problem).

or do you have any idea how to store profile pictures for every person in the database? in the planned game there will be over 6500 different persons. so storing them all by hand would take time :(

there is really no way of getting access to an image on phone storage via the app to show an image? something like specialFolderPath("downloads") or something like specialFolderPath("images") ?

what about apps like whatsapp that gain access to contacts, gallery and others. i only need access to a folder (e.g. in the download folder of my phone i built a folder called "images") where i can store all my images. then inside the app on a specific card i would say "show image... from "\download\images\...



PS: i found out that the path: "/mnt/sdcard/download" works... do you know anything if internal storage on android is named other than "sdcard" when there is an external sd card inserted?

kap1987
Posts: 21
Joined: Tue Feb 21, 2017 6:25 pm

Re: Sports Text Manager Game (Wrestling)...

Post by kap1987 » Sun Apr 02, 2017 9:35 am

With the full path mentioned before it works on 4 different phones with android 5,6 and 7. so this seems to be the default folder for downloads...

i found a solution for the image problem:
...
put "/mnt/sdcard/Download/" & gDataWrestler["gimmickname"] & ".jpg" /*gDataWrestler["image"]*/ into field "profileimage" of group "profilewrestler"
put field "profileimage" into gprofileimage
set the filename of image "profileimage" of group "profilewrestler" to gprofileimage
<-- this works finde for me as long as the pictures a stored in the download folder of the phone.


my actual problem is now how to save or update data in the database itself. remember: i have the sqlite-file of the database inside the downloads folder of the phone. on my stack i have a button to update the database in the game from this path. it all works fine...

now i want to update for example the "gimmickname" field of the database of a specific person.
e.g.: the person Chris Park (id=1) has the "gimmickname" = Abyss. Now i want to change the gimmickname to lets say : "The Monster"

i used this code to open the database, save the text of the field name to variable gupdatename and try to update the field "gimmickname" in the database with the text of variable gupdataname:
# open the database:
put revOpenDatabase("sqlite", "/mnt/sdcard/Download/runrevemails.sqlite", , , , ) into dbID

put field "name" of group "profilewrestler" into gupdatename
answer gupdatename
# up to here everything works... it answers the text inside the field "name" now inside the variable gupdatename...

# the following was a try at first to save the text of gupdatename to person "id=1" in the database...
put "UPDATE wrestler SET gimmickname = 'gupdatename' WHERE id = '1'" into sql
revExecuteSQL dbID, sql

revCloseDatabase dbID
My problem is that livecode changes the text of field gimmickname in the database for id 1 to the text: "gupdatename" and not to the text saved inside the variable gupdatename.

PS: problem solved with this:
put "UPDATE wrestler SET gimmickname=" & "'" & (item 1 of gupdatename) & "'" & "WHERE ID = '1' " into sql
The next step would be to change this not for a special id written in the script but for the highlighted person of the datagrid.

PS: checked with this code:
put "UPDATE wrestler SET gimmickname=" & "'" & (item 1 of gupdatename) & "'" & "WHERE ID =" & "'" & (item 1 of gprofileid2) & "'" into sql

Klaus
Posts: 9698
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Sports Text Manager Game (Wrestling)...

Post by Klaus » Mon Apr 03, 2017 2:59 pm

Hi kap,

Code: Select all

...
put field "name" of group "profilewrestler" into gupdatename
answer gupdatename
# up to here everything works... it answers the text inside the field "name" now inside the variable gupdatename...

# the following was a try at first to save the text of gupdatename to person "id=1" in the database...
put "UPDATE wrestler SET gimmickname = 'gupdatename' WHERE id = '1'" into sql
revExecuteSQL dbID, sql
revCloseDatabase dbID
...
My problem is that livecode changes the text of field gimmickname in the database for id 1 to the text: "gupdatename" and not to the text saved inside the variable gupdatename.
you are supplying the STRING "gupdatename" and not the content of the variable with that name!
This is how it works:
...
put "UPDATE wrestler SET gimmickname =" & "'" & gupdatename & "'" & "' WHERE id = '1'" into sql
...

Here two little functions that will make life with Livecode, and not only when working with databases, much easier:
## Put QUOTES areund a give string, saves a LOT of typing!

Code: Select all

function q tString
  return QUOTE & tString & QUOTE
end q

## Put SINGLE Quotes around a given string
function q2 tString
  return "'" & tString & "'"
end q2
...
put "UPDATE wrestler SET gimmickname =" & q2(gupdatename) && "WHERE id = '1'" into sql
...

Best

Klaus

kap1987
Posts: 21
Joined: Tue Feb 21, 2017 6:25 pm

Re: Sports Text Manager Game (Wrestling)...

Post by kap1987 » Fri Apr 07, 2017 7:02 pm

I got it working... I can now update a field in the database with the text entered into a field of the stack.

Next Problem: :roll:

I load the data of the database into a data grid. clicking on the name of a person in the data grid opens a pop up with detailed information about the person (same card). when i click on a special characteristic of a person (e.g. "disposition" a newly pop up shows the different possibilities to choose from. when clicking the button "update" the data is transfered to the database and updated in the data grid (lowest part of the card). but the data of field "dispostion" in the pop up of a person is not updated until i gob back to the data grid and click the persons name again.

how can i update the data in a field, when it has been updated in the database?

Klaus
Posts: 9698
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Sports Text Manager Game (Wrestling)...

Post by Klaus » Fri Apr 07, 2017 7:35 pm

Hi Kap,
kap1987 wrote:...when clicking the button "update" the data is transfered to the database and updated in the data grid (lowest part of the card).
but the data of field "dispostion" in the pop up of a person is not updated until i gob back to the data grid and click the persons name again.

how can i update the data in a field, when it has been updated in the database?
why not also update field "disposition" in the same handler where you update the database and datagrid? 8)


Best

Klaus

kap1987
Posts: 21
Joined: Tue Feb 21, 2017 6:25 pm

Re: Sports Text Manager Game (Wrestling)...

Post by kap1987 » Sat Apr 15, 2017 5:15 pm

Thx and sorry for the lately answer....

I now have a problem with my data grid... scrolling on android is working.

i used this code:
local sScrollerID

on preOpenCard

local tScrollerRect, tContentRect

// Only create a scroller on a mobile device
if environment() is not "mobile" then exit preOpenCard

// Set the area of the scroller
put the rect of group "scrollArea" into tScrollerRect

// Set the are of the content to be scrolled
put the left of group "DataGridWrestler",the top of group "DataGridWrestler",the right of group "DataGridWrestler",the formattedHeight of group "DataGridWrestler" into tContentRect

// Create the scroller control
mobileControlCreate "scroller", "loremScroll"
put the result into sScrollerID

// Set the properties of the scroller
mobileControlSet "loremScroll", "rect", tScrollerRect
mobileControlSet "loremScroll", "contentRect", tContentRect
mobileControlSet "loremScroll", "visible", true
mobileControlSet "loremScroll", "scrollingEnabled", true
mobileControlSet "loremScroll", "vIndicator", true
mobileControlSet "loremScroll", "vscroll", 0
end preOpenCard

on closeCard
// Delete the scroller
if environment() is not "mobile" then exit closeCard
mobileControlDelete sScrollerID
end closeCard

on scrollerDidScroll hOffset, vOffset
// When the user scrolls move the displayed content
set the vScroll of group "scrollArea" to vOffset
end scrollerDidScroll
i resized the data grid to height of 5000px to fit all data in the grid... is there a possibility to change the height of the grid dinamically. the data in the grid is dinamically changed, so the number of lines change aswell... it would be great to stick the height of the data grid to the number of lines in the grid.


So finally i need a code to save the actual number of rows in the data grid to a variable. and another code to pass this number x the height of 1 row in oixel to the data grid height.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”