PDA

View Full Version : 3 little problems


CT_Bolt
02-04-2006, 12:22 PM
OK I need to know:
1. How to make any *.Wav file play?
I know how to add unmodified *.Wavs but, when I modify any(all different) of them i get an error.

2. How to make a color in a BMP show up transparent with coding?

3. What an array looks like in this?

illfoundedmind
02-04-2006, 12:28 PM
1) files must be mono and cetrian specs.

2) You mean when creating the file? If so BMP aren't transparent use PNG (graphicgale woul be a program to look into)

3) a = { f = k, g = k }
a.f = k

Luaplayer.org

CT_Bolt
02-04-2006, 04:09 PM
:D:D Thank you, this helps me alot.:D:D
But, there isn't a way to specify a Transparent Color in Lua Script(not creating it, but thanx for the info).

Umm... what exactly are you showing me in #3.

Arrays(subscripts) I am used to look like ImgBoard(0),ImgBoard(1),ImgBoard(2),...
This looks like types(properties). I'll try to understand with this though.

modsyn
02-04-2006, 06:47 PM
lua uses tables. tables can look like arrays (java/c/c++ arrays) where you have

tab = {}
tab[1] = "Index One"
tab[2] = "Index Two"
or you can define them using named indexes (rather than numbered indexes) like
tab = {}
tab.one = "Index One"
tab.two = "Index Two"
tab is the variable name for a table variable. table values can be strings, numbers, or other tables.
the following is the same as the second definition:
tab = { one= "Index One", two = "Index Two" }
and for some very strange reason lua table indexes start at 1 instead of the usual 0 (like every other
language that uses arrays)

illfoundedmind
02-04-2006, 07:19 PM
that 1 thing pisses me off spent 1 hour debugging a app cuz that :(

:D:D Thank you, this helps me alot.:D:D
But, there isn't a way to specify a Transparent Color in Lua Script(not creating it, but thanx for the info).
I have the same question for the image.creation function is there a way to make the background transparent?

Umm... what exactly are you showing me in #3.

Arrays(subscripts) I am used to look like ImgBoard(0),ImgBoard(1),ImgBoard(2),...
This looks like types(properties). I'll try to understand with this though.
I think modsyn answered your question for the last one.

modsyn
02-04-2006, 07:54 PM
look at the docs for screen:blit(), the last argument is an alpha level. you can set the transparency that way.
i've never used it that way, though. i always just use precreated transparent pngs

illfoundedmind
02-05-2006, 08:45 AM
Thanks I did not know that. For the image creation function the default color is black which well doesn't work if you want to use layers. Thanks

CT_Bolt
02-06-2006, 08:43 AM
:P:D Thank you all so much for your help. :D:P
You both seem very understanding. :cool: I believe you have answered all my current questions.
So... now of course... I have more for you:

Q: How do you find a tables Lower and Upper Bounds?

Q: Is it possible to loop through the table indexes?

Q: Is this what it would look like?
for I = 1, 10 do
tab[i] = "Index" + I
end
If it's not please correct me.:/

modsyn
02-07-2006, 08:24 AM
somewhat, i would use
for i=1,table.getn(tab) do
tab[i] = "Index " .. i
end
.. is string concatenation (not +, that will get you an error)

CT_Bolt
02-07-2006, 12:03 PM
Wow you have been so helpful. :D Thank you so much. :D :mrgreen:
You get credit in my Lua Apps. ;) :)
Along with every one else that has helped me. Also when my beta versions are ready then you can test them if you want. :cool:

CT_Bolt
02-08-2006, 04:46 PM
Another question: How to pass image variables through a function?
function drawSection(DestImg, SrcImg, ...)
end
Why doesn't this work? :/:mad:

illfoundedmind
02-08-2006, 05:17 PM
???

You mean like this:

Image.load("graphics/tilesets/tileset".. currentmap .. ".png")

Currentmap being a varible??

CT_Bolt
02-09-2006, 12:40 AM
No, I mean when making my own function... Or maybe I just need to know how to make my own function. :| This is what it shows on the tutorial though. :/

I need to pass images like this:

-- ************************* Load Images ************************* -

-- Load Chipsets
ImgChipSet = {}
ImgChipSet[1] = {}

ImgChipSet[1][1] = Image.load("img/chipsets/Non Angled/00.png")


-- ***********************************************--
-- ***********************************************--
-- *******This is were I use what you wrote about*******--
for i=0,7 do
ImgChipSet[1][i+2] = Image.load("img/chipsets/Angled/00/0".. i .. ".png")
end
-- ***********************************************--
-- ***********************************************--
-- ***********************************************--

-- *************************************************************** --

drawSection(ImgChipSet[1][1], screen) -- This doesn't work.

-- ************************** Functions ************************** --

function drawSection(DestImg, SrcImg) -- There would be more variables if this was a real function.
-- It doesn't matter what goes in here yet.
end

-- *************************************************************** --
See what I mean?:| But I did use that too.;)
I don't see why it doesn't work, it's very frustrating. :mad:

This is what the error message says:
error: index.lua:22 attept to call global 'drawSection' (a nil value)
Error: No script file found.
Press start to restart
I've seen similar messages but not this. :(

romero126
02-09-2006, 05:35 AM
you have two options. for transparencies in color. if you want to create a transparant color (not image) you subtract the alphablend from the color
That means
alpha = .5 (thats half transparancy)
screen:fillRect(0,0, screen:width(), screen:height(), alpha- Color.new(0,0,255))

Another way to do this trick is with an image.
image:blit(x, y, Image source, [sourcex, sourcey, width, height], [alpha = true])
image = Image.load(filename/path)
screen:blit(x, y, image, alpha [example 0.5])

please note everything in brackets is optional.

CT_Bolt
02-09-2006, 11:22 AM
Thank you, I didn't know about that whole thing exactly. :D You have indeed helped me out. :cool: :/ Although I don't quite get it exactly :/ , could you please be a little more clear & explanatory.:)
You also recieve credit and beta testing(if you want to) for your kindness. :)

Any thoughts on my other problem??? :/:(

illfoundedmind
02-09-2006, 09:31 PM
Yes, you your commenting system is... interesting.
I'm unsure what you want to do with the images you load... do you just want to draw them on the screen? tell me exactly what you want to do and I'll write it the "proper" way.

modsyn
02-10-2006, 12:17 AM
This is what the error message says:
error: index.lua:22 attept to call global 'drawSection' (a nil value)
Error: No script file found.
Press start to restart
I've seen similar messages but not this. :(
oh. i see the problem. very similar to how you have to define functions in C, function delcarations (along with their
bodies) need to come before they are ever used. so, just put:
function drawSection( dest, src )
--bleh
end
somewhere at the top of your file before you do anything else and it should work.

illfoundedmind
02-10-2006, 10:10 AM
That is right I didn't scroll down to see there was more code in that piece. Kind of woundering wtf you were doing myself [~_~]

CT_Bolt
02-12-2006, 09:12 PM
illfoundedmind Wrote:
That is right I didn't scroll down to see there was more code in that piece. Kind of woundering wtf you were doing myself [~_~]
I don't know C or C++ yet, so I use languages that don't need functions to be at top(although it does make sense). If that's what you even mean.

Thanks again for every ones help. :D

illfoundedmind
02-13-2006, 05:07 PM
What are you up to coding? :D

CT_Bolt
02-13-2006, 08:24 PM
illfoundedmind wrote:

What are you up to coding? :D
I kinda thought that's what you meant and well... Sry, I'm not telling yet. ;) :P

Although, I suppose I will tell you a couple things:

1) It's a fun 2 Player Game(with 1 PSP)
2) It's basically a board game(or paper pencil) that has been around for a while.

Any guesses. ;) :) , and no it's not D&D(it's not even originally a paper and pencil game).
:o Oh and I have another few questions:

1) I need to keep the values of DelayCtr, CurrentRow, CurrentCol. I get an error message doing this:

-- ************************** Functions ************************** --

function DrawSection( DestImg, SrcImg, DestX, DestY, Row, Col, SrcWidth, SrcHeight, SpaceX, SpaceY )
DestImg:blit( DestX, DestY, SrcImg, (SrcWidth + SpaceX) * Row, (SrcHeight + SpaceX) * Col, SrcWidth, SrcHeight )

function Animate( DestImg, SrcImg, DestX, DestY, StartRow, EndRow, StartCol, EndCol, SrcWidth, SrcHeight, SpaceX, SpaceY, Delay )
DelayCtr = DelayCtr + 1

if Delay == DelayCtr then
DrawSection( screen, ImgFountain, CurrentRow, CurrentCol, 0, 0, SrcWidth, SrcHeight, SpaceX, SpaceY )

CurrentRow = CurrentRow + 1

if CurrentRow == EndRow then
CurrentRow = StartRow
lCurrentCol = CurrentCol + 1
end

if CurrentCol == EndCol then
CurrentCol = StartCol
CurrentRow = StartRow
end

DelayCtr = 0
end
end

function DrawSection( DestImg, SrcImg, DestX, DestY, Row, Col, SrcWidth, SrcHeight, SpaceX, SpaceY )
DestImg:blit( DestX, DestY, SrcImg, (SrcWidth + SpaceX) * Row, (SrcHeight + SpaceX) * Col, SrcWidth, SrcHeight )

end

-- *************************************************************** --
This is the error message:

error: index lua:4 attempt to perform arithmetic on global 'DelayCtr' (a nil value)
Error: No script found.

Press start to restart
2) I want to set CurrentRow to StartRow and CurrentCol to StartCol in the Animate function, but I don't know exactlly how to do it(with out messing other things up). Could you show me how? :/

3) I might need a list of the 'if... then' operaters(equal, not equal, greater than, less than, etc...).
Is this correct?

== is Equal to
>= is Greater Than or Equal to
<= is Less Than or Equal to
> is Greater Than
< is Less Than
~= is Not Equal to
4) How do you make optional parameters in the functions?
Is it: Optional Delay = 500, OR [Delay = 500], OR something else?

modsyn
02-13-2006, 11:45 PM
i'll take a go at some of those:

#1) you need to have those variables defined somewhere. the first time they are used it's on both sides of the
assignment statement ( DelayCtl = DelayCtl + 1 ). there's nothing wrong with that assignment as long as you
initialize DelayCtl somewhere. a simple statement at the top of the file (or anywhere before the function gets
called, really) that says "DelayCtl = 0" should fix that. you should do the same for the other variables, too.

#2) i'm not exactly sure what you mean, so i'll skip it...

#3) that list is good. you can also check for nil values by using
if varname then
--executes if the 'varname' variable is NOT nil
end
and
if not varname then
--executes if the 'varname' variable IS nil
end
#4) for optional parameters to a function, just have them in the function header. if they don't get passed then
the variables will be nil. for a better explanation, see this example - I have a function like this:
function graphicsPrint( text, color )
if not color then
color = Color.new( 255, 255, 255 )
end
screen:print( x, y, text, color )
end
i can call this function one of 2 ways:
graphicsPrint("This is some white text")
will print the text but since i didn't pass a 'color' value the variable 'color' will be nil, so the function handles that
situation by using 'if not color then ... '
if i wanted to print a certain color, i could use:
graphicsPrint("This is some bright blue text", Color.new(0,0,255))
since i passed it a valid color value it won't set color to white and it'll print out blue.

good luck on the game.

CT_Bolt
02-14-2006, 09:44 AM
Wow, thank you so much. :D :D You are a great help. :D :cool:

I think, I have maybe figure out #2 on my own now, but now I have 1 more question.

1) OK, this is my situation...

-- ************************** Functions ************************** --

function DrawSection( DestImg, SrcImg, DestX, DestY, Row, Col, SrcWidth, SrcHeight, SpaceX, SpaceY )
if not Row then Row = 0 end
if not Col then Col = 0 end
DestImg:blit( DestX, DestY, SrcImg, (SrcWidth + SpaceX) * Row, (SrcHeight + SpaceX) * Col, SrcWidth, SrcHeight )
end

function Animate( DestImg, SrcImg, DestX, DestY, StartRow, EndRow, StartCol, EndCol, SrcWidth, SrcHeight, SpaceX, SpaceY, Delay )

if not DelayCtr then DelayCtr = 0 end
if not StartRow then StartRow = 0 end
if not StartCol then StartCol = 0 end
if not CurrentRow then CurrentRow = StartRow end
if not CurrentCol then CurrentCol = StartCol end

DelayCtr = DelayCtr + 1

if DelayCtr >= Delay then

CurrentRow = CurrentRow + 1

if CurrentRow > EndRow then
CurrentRow = StartRow
CurrentCol = CurrentCol + 1
end

if CurrentCol > EndCol then
CurrentCol = StartCol
CurrentRow = StartRow
end
DelayCtr = 0
end
screen:print(100,0,Delay,Color.new(255,255,255))
DrawSection( DestImg, SrcImg, DestX, DestY, CurrentRow, CurrentCol, SrcWidth, SrcHeight, SpaceX, SpaceY )
end

-- *************************************************************** --

-- Load Lua Player Logo
ImgLuaPlayerLogo = Image.load("img/misc/luaplayer.png")

-- Load Fountain Image
ImgFountain = Image.load("img/misc/Blue Fountain.png")

while true do
pad = Controls.read()
if pad:start() then break end

screen:clear()
screen:blit((screen:width() - ImgLuaPlayerLogo:width()) / 2, (screen:height() - ImgLuaPlayerLogo:height()) / 2, ImgLuaPlayerLogo)

Animate( screen, ImgFountain, 0, 0, 0, 3, 0, 4, 107, 68, 0, 0, 100 )
Animate( screen, ImgFountain, 373, 0, 0, 3, 0, 4, 107, 68, 0, 0, 200 )
Animate( screen, ImgFountain, 0, 204, 0, 3, 0, 4, 107, 68, 0, 0, 300 )
Animate( screen, ImgFountain, 373, 204, 0, 3, 0, 4, 107, 68, 0, 0, 500 )

screen:flip()
screen.waitVblankStart()
end
When I send the Delay values to the Animate function, it only uses one value for all of them(which is 200 somehow), I need to use each seperate value for each one. How do I do that? :/

modsyn
02-14-2006, 01:10 PM
maybe you need to flip the screen at the end of the Animate function?

CT_Bolt
02-14-2006, 02:20 PM
:o Uhh... No that just made it worse.:/ Thanks for your help, though I need something to remeber the value of Delay, for when it is called next with the same parameters but, not for the other times when the Animate function is called. :| ;) :) Any other Ideas.

illfoundedmind
02-14-2006, 09:11 PM
x = 5
screen.waitVblankStart(x)

CT_Bolt
02-15-2006, 12:12 AM
I think that stops the screen, but I mean I need to keep the frame delay(time before next frame is drawn) of the current animation. :) Instead of all animations having the same one.;)

So I think I am going to use a timer and a well coded table to pass to the animate function which I probablly have to re-write completely.:(

If I am wrong please tell me. :) I almost hope I am.;)

illfoundedmind
02-15-2006, 10:46 AM
I think that stops the screen, but I mean I need to keep the frame delay(time before next frame is drawn) of the current animation. :) Instead of all animations having the same one.;)
x = 5
screen.waitVblankStart(x)

So I think I am going to use a timer and a well coded table to pass to the animate function which I probablly have to re-write completely.:(

If I am wrong please tell me. :) I almost hope I am.;)
could use os.time()

example:
background = Image.createEmpty(480, 272)
clockOfs = 150
clockWidth = 100
clockTextPosition = 85
clockBigMarkWidth = 7
clockSmallMarkWidth = 3
x0 = clockOfs
y0 = clockOfs - clockWidth
pi = 4*math.atan(1)
color = Color.new(0, 255, 0)
for i=0,60 do
x1 = math.sin(pi-i/60*2*pi) * clockWidth + clockOfs
y1 = math.cos(pi-i/60*2*pi) * clockWidth + clockOfs
background:drawLine(x0, y0, x1, y1, color)
xv = (x1 - clockOfs) / clockWidth
yv = (y1 - clockOfs) / clockWidth
if math.mod(i, 5) == 0 then
xt = xv * clockTextPosition + clockOfs
yt = yv * clockTextPosition + clockOfs
value = math.ceil(i / 5)
if value == 0 then
value = 12
end
background:print(xt, yt, value, color)
xv = xv * (clockWidth - clockBigMarkWidth) + clockOfs
yv = yv * (clockWidth - clockBigMarkWidth) + clockOfs
background:drawLine(x1, y1, xv, yv, color)
else
xv = xv * (clockWidth - clockSmallMarkWidth) + clockOfs
yv = yv * (clockWidth - clockSmallMarkWidth) + clockOfs
background:drawLine(x1, y1, xv, yv, color)
end
x0 = x1
y0 = y1
end
background:print(4, 4, "os.date: ", color)
background:print(4, 14, "digital: ", color)

while not Controls.read():start() do
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
time = os.time()
dateString = os.date("%c", time)
screen:print(84, 4, dateString, color)
dateFields = os.date("*t", time)
hour = dateFields.hour
if hour < 10 then
hour = "0" .. hour
end
min = dateFields.min
if min < 10 then
min = "0" .. min
end
sec = dateFields.sec
if sec < 10 then
sec = "0" .. sec
end
screen:print(84, 14, hour .. ":" .. min .. ":" .. sec, color)

hour = dateFields.hour
if hour > 12 then
hour = hour - 12
end
hour = hour + dateFields.min / 60 + dateFields.sec / 3600
x = math.sin(pi-hour/12*2*pi) * clockWidth / 3 * 2 + clockOfs
y = math.cos(pi-hour/12*2*pi) * clockWidth / 3 * 2 + clockOfs
screen:drawLine(clockOfs, clockOfs, x, y, color)

min = dateFields.min + dateFields.sec / 60
x = math.sin(pi-min/60*2*pi) * clockWidth + clockOfs
y = math.cos(pi-min/60*2*pi) * clockWidth + clockOfs
screen:drawLine(clockOfs, clockOfs, x, y, color)

x = math.sin(pi-dateFields.sec/60*2*pi) * clockWidth + clockOfs
y = math.cos(pi-dateFields.sec/60*2*pi) * clockWidth + clockOfs
screen:drawLine(clockOfs, clockOfs, x, y, color)

screen.waitVblankStart()
screen.flip()
end

CT_Bolt
02-15-2006, 12:13 PM
Hmm... a little commenting wouldn't kill ya'.;) I'll try to figure it out though. Thank you for this idea. :)
Anybody have other ideas about this? :)

illfoundedmind
02-15-2006, 10:11 PM
There is no other way >__> HAHAHA.

You can either slow down processing with the screen.waitVblankStart() or keep it in sync with system time os.time().
















There maybe another way...