forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Browsing in a text file and variables

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
imhotep



Joined: 13 Dec 2005
Posts: 41

PostPosted: Fri Mar 03, 2006 2:11 am    Post subject: Browsing in a text file and variables Reply with quote

hi, i've been somwhat struggling to create a lua script that is flexible
and smart to search through a text file to assign some values to variables.

here is an example text:

#charpic=patrick.png
#health=100
#type=enemy
#tileset=tiles/patrick_tile.png

what i would need is a script that searches one line, i thought i'd try this


Code:

filename="patrick.txt"

        file = io.input(filename, "r")
 
if file then
   for line in file:lines() do
         middle = string.sub(line, "=")
      if middle then
         key = string.sub(line, 2, middle-1)
         result = string.sub(line, middle + 1)
         character[key] = result
      end
   end
end

-- output etc



my problem is, if if add the picture wit the following code,

Code:

pix=Image.load(character.charpic)
screen:blit(100,100,pix)

a.s.o.



or if i try to assign a color with a variable, i always get errors, like image load error, or that i didn't do the color rgb syntax correctly.

also, my text is displayed with ascii characters that stand for tabs and breaks. is there a way to erase these?
because i think they are added to the variable .... perhaps ....

another question: is there a way to get rid of the "="s and to make it more flexible in case of a mistyping?thanks

--imhotep--
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Fri Mar 03, 2006 5:17 am    Post subject: Re: Browsing in a text file and variables Reply with quote

imhotep wrote:
or if i try to assign a color with a variable, i always get errors, like image load error, or that i didn't do the color rgb syntax correctly.


The reason may be that it is a string and the color constructor expects a number. See the Lua manual how to convert it.

In general maybe it is better to use Lua itself to help you:

level.lua:
Code:

charpic="patrick.png"
health=100
type="enemy"
"tileset="tiles/patrick_tile.png"


and then simply dofile("level.lua")
Back to top
View user's profile Send private message
imhotep



Joined: 13 Dec 2005
Posts: 41

PostPosted: Fri Mar 03, 2006 8:15 am    Post subject: Reply with quote

yup, thanks.
i'll try to convert it.
but i'd like to work with text files as i don't have to include specific files

i'd like this to be like a database for all objects/obstacles/enemies in the level and their stats etc.

but i guess i could go with your suggestion and just include the lua file with a variable for the file name.

thx
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group