Page 8 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Sun Mar 27, 2016 8:14 pm
by HenryRichard
Though if you're going to use math.random you should put math.randomseed(os.time()) at the beginning of your code. You could also just use rng.lua, which is "more random" and is generally more useful.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Mar 27, 2016 8:15 pm
by PixelPest
HenryRichard wrote:Though if you're going to use math.random you should put math.randomseed(os.time()) at the beginning of your code.
Or you could use RNG

Re: Need help with lua? - LunaLua General Help

Posted: Sun Mar 27, 2016 8:16 pm
by HenryRichard
Yeah... just like I said...

Re: Need help with lua? - LunaLua General Help

Posted: Sun Mar 27, 2016 8:19 pm
by Emral
HenryRichard wrote:Yeah... just like I said...
I don't see the point in trying to salvage math.random's functionality if using rng is just so much easier.

Code: Select all

local rng = API.load("rng")
local randomVariable = rng.random(1, 10)
http://wohlsoft.ru/pgewiki/Rng.lua

Re: Need help with lua? - LunaLua General Help

Posted: Sun Mar 27, 2016 10:35 pm
by HenryRichard
Is there an easy-ish way I could render a bunch of sprites in 3-Dimensional space? I want some that face the camera and some that have a fixed orientation (that is, they don't move with the camera), though I can make do with only the former.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 28, 2016 2:11 am
by Quantumenace
Sort of. To manipulate a sprite like that you can draw a pair of triangles that use the sprite graphic as a texture. Not sure if you can load the default gif images like that though, it says only to use png.

Edit:Oops, I forgot you already made the level with spinning planets so you know that already. What type of rotation do you mean, is it like a parallax thing?

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 28, 2016 4:29 pm
by HenryRichard
I don't think you understand what I mean. I want to make a 3D space and draw sprites in it. I'm sure it would utilize some OpenGL functions, though I'm really not sure how to go about it.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 28, 2016 4:55 pm
by Quantumenace
If you're asking whether the GL functions actually have support of x,y,z coordinates I have no idea. My point is, you can get a 3D perspective by applying a parallax transform to your coordinates.

Image

Code: Select all

angle = 0
bb = Graphics.loadImage("bb.png")

function onCameraUpdate()
local cam = Camera.get()[1]; local x0 = cam.x+0.5*cam.width; local y0 = cam.y+0.5*cam.height
local basedepth = 1000
local priority = -96
local texture = bb
local w,h = 128,128
angle=angle+math.pi/90; if angle > math.pi then angle = angle -2*math.pi end
local s = math.sin(angle); local c = math.cos(angle)
local wc = 0.5*w*c; local ws = 0.5*w*s; local hc = 0.5*h*c; local hs = 0.5*h*s
local x,y,z=-199280,-200288,256

local xyz = {x-wc,y+0.5*h,z-ws,x+wc,y+0.5*h,z+ws,x+wc,y-0.5*h,z+ws,
			x-wc,y+0.5*h,z-ws,x-wc,y-0.5*h,z-ws,x+wc,y-0.5*h,z+ws}
local xy = {}

for i=1,#xyz,3 do
	z=math.max(xyz[i+2],-basedepth+.01)
	table.insert(xy,0.5*cam.width+(xyz[i]-x0)*basedepth/(z+basedepth))
	table.insert(xy,0.5*cam.height+(xyz[i+1]-y0)*basedepth/(z+basedepth))
end

	local txs = {0,1,1,1,1,0,0,1,0,0,1,0}

	Graphics.glDraw{texture=texture, textureCoords=txs,vertexCoords=xy, priority=priority}
end

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 28, 2016 5:28 pm
by Hoeloe
Quantumenace wrote:If you're asking whether the GL functions actually have support of x,y,z coordinates I have no idea.
They don't. I was, however, working on a 3D renderer a while ago, but it was too slow to be of any use. I got rid of all the old videos I had of it, but it was very basic. Essentially I could load in a .obj file and move it around a 3D scene, but more than about 200 triangles dropped the framerate far too much to be useful.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 28, 2016 5:36 pm
by HenryRichard
You wouldn't happen to have any of that code anymore, would you? I probably won't be needing anywhere near 200 triangles for what I'm doing (probably 50 at most) and I may be able to salvage it.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 28, 2016 6:20 pm
by Hoeloe
HenryRichard wrote:You wouldn't happen to have any of that code anymore, would you? I probably won't be needing anywhere near 200 triangles for what I'm doing (probably 50 at most) and I may be able to salvage it.
Ehhh... it has other problems as well. I still have the library around somewhere, but it's not designed for layering sprites, more for actual perspective 3D projection. Think N64.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 29, 2016 6:16 pm
by pal4
I tried to pull off a lunalua code for a real red birdo complete with behavior from Pge wiki. It uses a "simple" lunalua code to make Birdo randomly shoot fireballs in place of eggs. The code looks like this:
local hasGenerated = false;
local ran;

function onLoop()
tableOfBirdo = NPC.get(39, -1);
tableOfBirdoEggs = NPC.get(40, -1);

if(tableOfBirdo[1] ~= nil) then
if(tonumber(tableOfBirdo[1]:mem(0xF0, FIELD_DFLOAT)) == 1) then
if(hasGenerated ~= true) then
ran = math.random(0, 2);
hasGenerated = true;
end
if(ran == 2) then
if(table.getn(tableOfBirdoEggs) > 0) then
tableOfBirdoEggs[table.getn(tableOfBirdoEggs)].id = 282;
playSFX(42);
end
end
end
if(tonumber(tableOfBirdo[1]:mem(0xF8, FIELD_DFLOAT)) == 280) then
hasGenerated = false;
end
end
end
Unfortunately, Birdo is only changed visually; his behavior isn't changed in any way. He still shoots nothing but eggs. Even after copying and pasting the proper code (the downloaded code looks nothing like this), constantly saving my level with the code, and trying to update smbx to match the version of lunalua, still nothing changes!

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 29, 2016 10:09 pm
by HenryRichard
Show us a screenshot of the folder that the level is in.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Mar 31, 2016 7:28 pm
by pal4
HenryRichard wrote:Show us a screenshot of the folder that the level is in.
How do I do that?

Re: Need help with lua? - LunaLua General Help

Posted: Thu Mar 31, 2016 7:31 pm
by PixelPest
pal4 wrote:
HenryRichard wrote:Show us a screenshot of the folder that the level is in.
How do I do that?
Use snipping tool, another screenshot tool, or the "Print Screen" button on your keyboard to take a screenshot of the folder the level it's in and then upload it to imgur.com

Re: Need help with lua? - LunaLua General Help

Posted: Fri Apr 01, 2016 5:05 pm
by pal4
PixelPest wrote:Use snipping tool, another screenshot tool, or the "Print Screen" button on your keyboard
Unfortunately I don't have any tools in my folders and no printer. So I can't do any of those.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Apr 01, 2016 5:07 pm
by Emral
pal4 wrote:
PixelPest wrote:Use snipping tool, another
Unfortunately I don't have any tools in my folders and no printer. So I can't do any of those.
Snipping Tool is a program which comes preinstalled on Windows operating systems since vista. I doubt you don't have it.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Apr 01, 2016 5:11 pm
by pal4
Er, how go I upload a picture on these forums?

Re: Need help with lua? - LunaLua General Help

Posted: Fri Apr 01, 2016 5:16 pm
by Emral

Re: Need help with lua? - LunaLua General Help

Posted: Sat Apr 02, 2016 4:05 pm
by Ness-Wednesday
What does it mean if I get an error saying that ( is expected near if?
This doesn't make sense to me.