Log In  
Follow
Peej
Follow

Hello all.
I'm doing alright at the moment with the new Pico-8 and I'm typing away happily.
One problem though.... I seem to be typing 'self' a LOT and using loads of valuable characters and/or tokens.

Is there a simple way to cut back on the number of times I have to use 'self'?

Its probably really complicated and I thought I was doing well...

Many thanks in advance
Peej

P#95156 2021-07-21 21:42

Hello all, again.
I'm trying to get my head around tables.
I thought it would be a good idea to store a table of the possible modes and enemy can be in, chase, pause, detect etc.
So the enemy could only be in one mode at a time without all the if statements.

I tried this:

function add_new_enemy(x,y,type)
    add(enemy,{
        mode={},
        add(mode,{1,2,3}),
        x=x,
        y=y.... etc.

Adding a table called 'mode' with values 1,2,3 (All in the name of experimentation.)

Similar to the last problem I asked about, I'm trying to just print the first value of 'mode'.
In the _draw I have this:

print(enemy[1].mode[1])

But that print NIL

What am I doing wrong? is my table all wrong are is my print statement wrong?

Many thanks
Peej

P#95007 2021-07-17 22:16

Embarrassing question but please be gentle. I'm very new to all this.
I have this code: (Lower down there). It's a bit mock up really for this question.

Lower down still in my code I'm working on a collision detection bit that needs, among other things, the value of x.
As you can see, it's all referencing 'self' and I have NO IDEA how to get the x value from this line:

spr(17,self.x,self.y,1,1,false)

Would someone please help a noob out.

Many thanks
Peej

function add_new_enemy()
    add(enemy,{
        x=80,
        y=96,
        w=8,
        h=8,
        dx=rnd(2)-1,
        dy=rnd(2)-1,
        life=20,
        draw=function(self)
            spr(17,self.x,self.y,1,1,false)
        end,

        update=function(self)
         self.x+=self.dx
         self.y+=self.dy
         self.life-=1
            if self.life<0 then
             del(enemy,self)
            end
        end
    })
end
P#94873 2021-07-15 00:15

Hello all.
I'm brand new to all things Pico 8, having dabbled with programming since the 80s.
I'm having LOTS of problems though.

I added particles to my platform player.
I saw a tutorial about adding objects and function within them, so I tried to change my particle system.
It broke. The error says: Unclosed { but I can't find where I've gone wrong.
I apologise if this isn't how to post code on this.
Can someone help out, please. (This is trimmed down in the hope I don't over stay my welcome!)

function _init()
....
particle={}
end

function add_new_particle(x,y,die,dx,dy,grav,grow,shrink,r,c_table)
add(particle,{
x=x,
y=y,
t=0,
die=die,
dx=dx,
dy=dy,
grav=grav,
grow=grow,
shrink=shrink,
r=r,
c=0,
c_table=c_table

    draw=function(self)
     if self.r<=1 then
      pset(self.x,self.y,self.c)
     else
      circfill(self.x,self.y,self.r,self.c)
     end
    end,

    update=function(self)
     self.x+=self.dx
     self.y+=self.dy
      if self.grav then self.dy+=.5 end
      if self.grow then self.r+=.1 end
      if self.shrink then self.r-=.2 end
     self.t+=1

      if self.t>self.die then del(particle,self) end

        if self.t/self.die < 1/#self.c_table then   
         self.c=self.c_table[1]
        elseif self.t/self.die < 2/#self.c_table then
         self.c=self.c_table[2]
        elseif self.t/self.die < 3/#self.c_table then
         self.c=self.c_table[3]
        else
         self.c=self.c_table[4]
        end
    end
})
end

function dust()
  add_new_particle(plyr.x,plyr.y,10+rnd(7),rnd(2)-1,rnd(.3)-.4,false,true,true,3,{4,4,5,5})
end

 function runs()
  add_new_particle(plyr.x,plyr.y,10+rnd(7),rnd(2)-1,rnd(1)-0.5,false,false,true,2,{4,4,5,5})
 end

When the player lands on a platform, I have this: But it doesn't get this far.
dust()
sfx(0)

I haven't even figured what to put in the _draw function yet.

I hope this isn't too much to see what I'm trying to do and makes a bit of sense to someone.
Thanks for your time.
Peej

P#94770 2021-07-12 21:51

Follow Lexaloffle:        
Generated 2021-07-28 05:24:37 | 0.093s | Q:9