Advertising (This ad goes away for registered users. You can Login or Register)

[LUA] Need help with code plz

Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

qwikrazor87 wrote:You need to call loadgame() after calling dofile("saveload.lua")

Code: Select all

dofile("saveload.lua")

loaded = loadgame()

if loaded then
  os.message("Game loaded successfully")
else
  os.message("Game could not be loaded")
end
I did do that but when I press load and then start the game it doesn't apply the variables i saved.
Advertising
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 »

dragonxtamer596 wrote:I did do that but when I press load and then start the game it doesn't apply the variables i saved.
I just tested it out and it works.
In script.lua I did this.

Code: Select all

savegame()
loadgame()
os.message(area)
--message popped up with 1
then I did this

Code: Select all

area = 2
savegame()
loadgame()
os.message(area)
--message popped up with 2
Which variables are you talking about, and when do you save the game?
Advertising
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

qwikrazor87 wrote:
dragonxtamer596 wrote:I did do that but when I press load and then start the game it doesn't apply the variables i saved.
I just tested it out and it works.
In script.lua I did this.

Code: Select all

savegame()
loadgame()
os.message(area)
--message popped up with 1
then I did this

Code: Select all

area = 2
savegame()
loadgame()
os.message(area)
--message popped up with 2
Which variables are you talking about, and when do you save the game?
Variables
In town.lua

Code: Select all

if not dagger1 then
dagger1 = 1
end
if not axe1 then
axe1 = 0
end
if not broadsword1 then
broadsword1 = 0
end
if not elucidator1 then
elucidator1 = 0
end
if not morningstar1 then
morningstar1 = 0
end
if not spear1 then
spear1 = 0
end
if not scimitar1 then
scimitar1 = 0
end
if not kopesh1 then
kopesh1 = 0
end
if not cloth1 then
cloth1 = 1
end
if not leather1 then
leather1 = 0
end
if not mail1 then
mail1 = 0
end
if not black1 then
black1 = 0
end
if not steel1 then
steel1 = 0
end
if not holy1 then
holy1 = 0
end
if not weapon then
weapon = "dagger"
end
if not armor then
armor = "cloth"
end

if not Level then
Level = 1
end
if not Experience then
Experience = 0
end
if not attributes then
attributes = 0
end
if not nextlevel then
nextlevel = 8
end
if not mhealth then
mhealth = 0
end
if not mmana then
mmana = 0
end
if not damage1 then
damage1 = 0
end
if not defence1 then
defence1 = 0
end

if not myCash then
myCash = 0
end
if not tarea then
tarea = 1
end
if not area then
area = 1
end

if not hpotioncost then
hpotioncost = 50
end
if not mpotioncost then
mpotioncost = 20
end
if not hpotionsell then
hpotionsell = 25
end
if not mpotionsell then
mpotionsell = 10
end

if not axebuy then
axebuy = 1500
end
if not broadswordbuy then
broadswordbuy = 3000
end
if not morningstarbuy then
morningstarbuy = 2250
end
if not spearbuy then
spearbuy = 1250
end
if not scimitarbuy then
scimitarbuy = 2500
end
if not kopeshbuy then
kopeshbuy = 500
end
if not leatherbuy then
leatherbuy = 1000
end
if not mailbuy then
mailbuy = 1500
end
if not blackbuy then
blackbuy = 1800
end
if not steelbuy then
steelbuy = 2550
end
if not holybuy then
holybuy = 6000
end

if not daggersell then
daggersell = 25
end
if not axesell then
axesell = 375
end
if not broadswordsell then
broadswordsell = 750
end
if not morningstarsell then
morningstarsell = 550
end
if not spearsell then
spearsell = 300
end
if not scimitarsell then
scimitarsell = 625
end
if not kopeshsell then
kopeshsell = 125
end
if not clothsell then
clothsell = 125
end
if not leathersell then
leathersell = 250
end
if not mailsell then
mailsell = 375
end
if not blacksell then
blacksell = 450
end
if not steelsell then
steelsell = 625
end
if not holysell then
holysell = 1500
end

if not hpotions then
hpotions = 0
end
if not mpotions then
mpotions = 0
end

if not healthbar then
healthbar = 10
end
if not manabar then
manabar = 10
end

if not hattributes then
hattributes = 0
end
if not mattributes then
mattributes = 0
end
if not health then
health = 100 + mhealth
end
if not mana then
mana = 100 + mmana
end
Where I save
ingamemenu.lua

Code: Select all

green = color.new(0, 255, 0)
lgreen = color.new(0,128,0)
white = color.new(255,255,255)
brown = color.new(156,90,60)
red = color.new(255,0,0)
blue = color.new(0,0,255)
black = color.new(0,0,0)
redD = color.new(177,7,12)

block1 = image.create(1,16,redD)

block2 = image.create(65,1,redD)

Pointer = { x = 165, y = 153}

Pointer1 = { x = 165, y = 11}

function checkcontrols()
controls.read()
    if Block1[1].y == 11 then
      pointer = image.load("Images/pointer.png")
      pointer:blit(Pointer.x,Pointer.y)
      end
    if controls.press("right") and Pointer.x <= 368 and Block1[1].y == 11 then
      Pointer.x = Pointer.x + 29
     end
    if controls.press("left") and Pointer.x >= 194 and Block1[1].y == 11 then
      Pointer.x = Pointer.x - 29
     end
    if controls.press("down") and Pointer.y <= 153 and Block1[1].y == 11 then
      Pointer.y = Pointer.y + 29
     end
    if controls.press("up") and Pointer.y >= 182 and Block1[1].y == 11 then
      Pointer.y = Pointer.y - 29
     end
   if controls.press("cross") and Pointer.x == 165 and Pointer.y == 153 and Block1[1].y == 11 and axe1 >= 1 then
      weapon = "axe"
     end
   if controls.press("cross") and Pointer.x == 194 and Pointer.y == 153 and Block1[1].y == 11 and broadsword1 >= 1 then
     weapon = "broadsword"
     end
   if controls.press("cross") and Pointer.x == 223 and Pointer.y == 153 and Block1[1].y == 11 and elucidator1 >= 1 then
     weapon = "elucidator"
     end
   if controls.press("cross") and Pointer.x == 252 and Pointer.y == 153 and Block1[1].y == 11 and dagger1 >= 1 then
     weapon = "dagger"
     end
   if controls.press("cross") and Pointer.x == 281 and Pointer.y == 153 and Block1[1].y == 11 and morningstar1 >= 1 then
     weapon = "morningstar"
     end
   if controls.press("cross") and Pointer.x == 310 and Pointer.y == 153 and Block1[1].y == 11 and spear1 >= 1 then
     weapon = "spear"
     end
   if controls.press("cross") and Pointer.x == 339 and Pointer.y == 153 and Block1[1].y == 11 and kopesh1 >= 1 then
     weapon = "kopesh"
     end
   if controls.press("cross") and Pointer.x == 368 and Pointer.y == 153 and Block1[1].y == 11 and scimitar1 >= 1 then
     weapon = "scimitar"
     end

if controls.press("cross") and Pointer.x == 165 and Pointer.y == 182 and Block1[1].y == 11 and cloth1 >= 1 then
      armor = "cloth"
     end
   if controls.press("cross") and Pointer.x == 194 and Pointer.y == 182 and Block1[1].y == 11 and black1 >= 1 then
     armor = "black"
     end
   if controls.press("cross") and Pointer.x == 223 and Pointer.y == 182 and Block1[1].y == 11 and holy1 >= 1 then
     armor = "holy"
     end
   if controls.press("cross") and Pointer.x == 252 and Pointer.y == 182 and Block1[1].y == 11 and steel1 >= 1 then
     armor = "steel"
     end
   if controls.press("cross") and Pointer.x == 281 and Pointer.y == 182 and Block1[1].y == 11 and leather1 >= 1 then
     armor = "leather"
     end
   if controls.press("cross") and Pointer.x == 310 and Pointer.y == 182 and Block1[1].y == 11 and mail1 >= 1 then
     armor = "mail"
     end
     
if Pointer.x == 165 and Pointer.y == 153 then
        screen.print(170,101,"Number of axes: " .. axe1,black)
     end
   if Pointer.x == 194 and Pointer.y == 153 then
        screen.print(170,101,"Number of broadswords: " .. broadsword1,black)     
     end
   if Pointer.x == 223 and Pointer.y == 153 then
        screen.print(170,101,"Number of elucidators: " .. elucidator1,black)     
     end
   if Pointer.x == 252 and Pointer.y == 153 then
        screen.print(170,101,"Number of daggers: " .. dagger1,black)     
     end
   if Pointer.x == 281 and Pointer.y == 153 then
        screen.print(170,101,"Number of morningstars: " .. morningstar1,black)     
     end
   if Pointer.x == 310 and Pointer.y == 153 then
        screen.print(170,101,"Number of spears: " .. spear1,black)     
     end
   if Pointer.x == 339 and Pointer.y == 153 then
        screen.print(170,101,"Number of kopeshes: " .. kopesh1,black)     
     end
   if Pointer.x == 368 and Pointer.y == 153 then
        screen.print(170,101,"Number of scimitars: " .. scimitar1,black)     
     end

if Pointer.x == 165 and Pointer.y == 182 then
        screen.print(170,101,"Number of cloth suits: " .. cloth1,black)
     end
   if Pointer.x == 194 and Pointer.y == 182 then
        screen.print(170,101,"Number of black suits: " .. black1,black)     
     end
   if Pointer.x == 223 and Pointer.y == 182 then
        screen.print(170,101,"Number of holy suits: " .. holy1,black)     
     end
   if Pointer.x == 252 and Pointer.y == 182 then
        screen.print(170,101,"Number of steel suits: " .. steel1,black)     
     end
   if Pointer.x == 281 and Pointer.y == 182 then
        screen.print(170,101,"Number of leather suits: " .. leather1,black)     
     end
   if Pointer.x == 310 and Pointer.y == 182 then
        screen.print(170,101,"Number of mail suits: " .. mail1,black)     
     end
      
  if Block1[1].y == 29 then
    ingameitems = image.load("Images/ingameitems.png")
      ingameitems:blit(146,1)
    pointer1 = image.load("Images/pointer.png")
      pointer1:blit(Pointer1.x,Pointer1.y)
      end
    if controls.press("right") and Pointer1.x <= 426 and Block1[1].y == 29 then
      Pointer1.x = Pointer1.x + 29
     end
    if controls.press("left") and Pointer1.x >= 194 and Block1[1].y == 29 then
      Pointer1.x = Pointer1.x - 29
     end
    if controls.press("up") and Pointer1.y >= 40 and Block1[1].y == 29 then
      Pointer1.y = Pointer1.y - 29
     end
    if controls.press("down") and Pointer1.y <= 215 and Block1[1].y == 29 then
      Pointer1.y = Pointer1.y + 29
     end
     
     if Block1[1].y == 48 then

     end 
     
     if Block1[1].y == 67 then
    blank = image.load("Images/blank.png")
    blank:blit(146,1)
     if controls.press("cross") then 
   saved = savegame()
   if saved then
   os.message("Game saved successfully")
   else
   os.message("Game could not be saved")
   end
     end 
     end 

     if Block1[1].y == 87 then
    blank:blit(146,1)
     if controls.press("cross") then        
      if area == 1 then
        dofile("town.lua") 
       elseif area == 2 then
        dofile("enviroment.lua") 
     end
     end
     end

     if controls.press("r") then 
       if Block1[1].y == 11 then
       Block1[1].y = Block1[1].y + 18
       Block1[2].y = Block1[2].y + 18
       Block2[1].y = Block2[1].y + 18
       Block2[2].y = Block2[2].y + 18

    elseif Block1[1].y == 29 then
       Block1[1].y = Block1[1].y + 19
       Block1[2].y = Block1[2].y + 19
       Block2[1].y = Block2[1].y + 19
       Block2[2].y = Block2[2].y + 19

    elseif Block1[1].y == 48 then
       Block1[1].y = Block1[1].y + 19
       Block1[2].y = Block1[2].y + 19
       Block2[1].y = Block2[1].y + 19
       Block2[2].y = Block2[2].y + 19

    elseif Block1[1].y == 67 then
       Block1[1].y = Block1[1].y + 20
       Block1[2].y = Block1[2].y + 20
       Block2[1].y = Block2[1].y + 20
       Block2[2].y = Block2[2].y + 20
    
   elseif Block1[1].y == 87 then
       Block1[1].y = Block1[1].y - 76 
       Block1[2].y = Block1[2].y - 76  
       Block2[1].y = Block2[1].y - 76 
       Block2[2].y = Block2[2].y - 76 
     end
     end

     if controls.press("l") then
       if Block1[1].y == 11 then
       Block1[1].y = Block1[1].y + 76
       Block1[2].y = Block1[2].y + 76
       Block2[1].y = Block2[1].y + 76
       Block2[2].y = Block2[2].y + 76

    elseif Block1[1].y == 29 then
       Block1[1].y = Block1[1].y - 18 
       Block1[2].y = Block1[2].y - 18 
       Block2[1].y = Block2[1].y - 18 
       Block2[2].y = Block2[2].y - 18

    elseif Block1[1].y == 48 then
       Block1[1].y = Block1[1].y - 19
       Block1[2].y = Block1[2].y - 19
       Block2[1].y = Block2[1].y - 19
       Block2[2].y = Block2[2].y - 19

    elseif Block1[1].y == 67 then
       Block1[1].y = Block1[1].y - 19
       Block1[2].y = Block1[2].y - 19
       Block2[1].y = Block2[1].y - 19
       Block2[2].y = Block2[2].y - 19

    elseif Block1[1].y == 87 then
       Block1[1].y = Block1[1].y - 20
       Block1[2].y = Block1[2].y - 20 
       Block2[1].y = Block2[1].y - 20 
       Block2[2].y = Block2[2].y - 20 
     end
     end
     end


Block1 = {}
Block1[1] = { x = 9, y = 11, height = block1:height(), width = block1:width() }
Block1[2] = { x = 73, y = 11, height = block1:height(), width = block1:width() }

Block2 = {}
Block2[1] = { x = 9, y = 11, height = block2:height(), width = block2:width() }
Block2[2] = { x = 9, y = 26, height = block2:height(), width = block2:width() }

background = image.load("Images/ingameequipment.png")

while true do
   
screen.clear()

background:blit(0,0)
   
checkcontrols()
  
if controls.press("start") then 
screenpic("ms0:/PSP/PHOTO")
end
   
   for a = 1,2 do
     block1:blit(Block1[a].x,Block1[a].y)
   end

   for a = 1,2 do
     block2:blit(Block2[a].x,Block2[a].y)
   end

   screen.print(42,251,myCash,black)

if weapon == "dagger" and Block1[1].y == 11 then
dagger=image.load("Images/dagger.png")
dagger:blit(204,49)
end

if weapon == "elucidator" and Block1[1].y == 11 then
elucidator=image.load("Images/elucidator.png")
elucidator:blit(204,49)
end

if weapon == "axe" and Block1[1].y == 11 then
axe=image.load("Images/axe.png")
axe:blit(204,49)
end

if weapon == "broadsword" and Block1[1].y == 11 then
broadsword=image.load("Images/broadsword.png")
broadsword:blit(204,49)
end

if weapon == "morningstar" and Block1[1].y == 11 then
morningstar=image.load("Images/morningstar.png")
morningstar:blit(204,49)
end

if weapon == "spear" and Block1[1].y == 11 then
spear=image.load("Images/spear.png")
spear:blit(204,49)
end

if weapon == "scimitar" and Block1[1].y == 11 then
scimitar=image.load("Images/scimitar.png")
scimitar:blit(204,49)
end

if weapon == "kopesh" and Block1[1].y == 11 then
kopesh=image.load("Images/kopesh.png")
kopesh:blit(204,49)
end

screen.waitvblankstart()
screen.flip()

end
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 »

I just compared all the variables and they are all there.

Need some cleaning up on your code.
Let's review your code.
I'll use some quotes so I can use other bbcodes.
[spoiler]
green = color.new(0, 255, 0)
lgreen = color.new(0,128,0)
white = color.new(255,255,255)
brown = color.new(156,90,60)
red = color.new(255,0,0)
blue = color.new(0,0,255)
black = color.new(0,0,0)
redD = color.new(177,7,12)

block1 = image.create(1,16,redD)

block2 = image.create(65,1,redD)

Pointer = { x = 165, y = 153}

Pointer1 = { x = 165, y = 11}

function checkcontrols()
controls.read()
--Here you can see the statement Block1[1].y == 11 is used a lot here
if Block1[1].y == 11 then
--Here is a bad way to load images, as long as Block1[1].y == 11 it's gonna keep on loading the image, you should load this image outside of the loop or use a statement to check if it's loaded or not.
pointer = image.load("Images/pointer.png")
pointer:blit(Pointer.x,Pointer.y)
end
if controls.press("right") and Pointer.x <= 368 and Block1[1].y == 11 then
Pointer.x = Pointer.x + 29
end
if controls.press("left") and Pointer.x >= 194 and Block1[1].y == 11 then
Pointer.x = Pointer.x - 29
end
if controls.press("down") and Pointer.y <= 153 and Block1[1].y == 11 then
Pointer.y = Pointer.y + 29
end
if controls.press("up") and Pointer.y >= 182 and Block1[1].y == 11 then
Pointer.y = Pointer.y - 29
end
--controls.press("cross") is used a lot here too.
if controls.press("cross") and Pointer.x == 165 and Pointer.y == 153 and Block1[1].y == 11 and axe1 >= 1 then
weapon = "axe"
end
if controls.press("cross") and Pointer.x == 194 and Pointer.y == 153 and Block1[1].y == 11 and broadsword1 >= 1 then
weapon = "broadsword"
end
if controls.press("cross") and Pointer.x == 223 and Pointer.y == 153 and Block1[1].y == 11 and elucidator1 >= 1 then
weapon = "elucidator"
end
if controls.press("cross") and Pointer.x == 252 and Pointer.y == 153 and Block1[1].y == 11 and dagger1 >= 1 then
weapon = "dagger"
end
if controls.press("cross") and Pointer.x == 281 and Pointer.y == 153 and Block1[1].y == 11 and morningstar1 >= 1 then
weapon = "morningstar"
end
if controls.press("cross") and Pointer.x == 310 and Pointer.y == 153 and Block1[1].y == 11 and spear1 >= 1 then
weapon = "spear"
end
if controls.press("cross") and Pointer.x == 339 and Pointer.y == 153 and Block1[1].y == 11 and kopesh1 >= 1 then
weapon = "kopesh"
end
if controls.press("cross") and Pointer.x == 368 and Pointer.y == 153 and Block1[1].y == 11 and scimitar1 >= 1 then
weapon = "scimitar"
end
if controls.press("cross") and Pointer.x == 165 and Pointer.y == 182 and Block1[1].y == 11 and cloth1 >= 1 then
armor = "cloth"
end
if controls.press("cross") and Pointer.x == 194 and Pointer.y == 182 and Block1[1].y == 11 and black1 >= 1 then
armor = "black"
end
if controls.press("cross") and Pointer.x == 223 and Pointer.y == 182 and Block1[1].y == 11 and holy1 >= 1 then
armor = "holy"
end
if controls.press("cross") and Pointer.x == 252 and Pointer.y == 182 and Block1[1].y == 11 and steel1 >= 1 then
armor = "steel"
end
if controls.press("cross") and Pointer.x == 281 and Pointer.y == 182 and Block1[1].y == 11 and leather1 >= 1 then
armor = "leather"
end
if controls.press("cross") and Pointer.x == 310 and Pointer.y == 182 and Block1[1].y == 11 and mail1 >= 1 then
armor = "mail"
end

--Pointer.y == 153 is used a lot here
if Pointer.x == 165 and Pointer.y == 153 then
screen.print(170,101,"Number of axes: " .. axe1,black)
end
if Pointer.x == 194 and Pointer.y == 153 then
screen.print(170,101,"Number of broadswords: " .. broadsword1,black)
end
if Pointer.x == 223 and Pointer.y == 153 then
screen.print(170,101,"Number of elucidators: " .. elucidator1,black)
end
if Pointer.x == 252 and Pointer.y == 153 then
screen.print(170,101,"Number of daggers: " .. dagger1,black)
end
if Pointer.x == 281 and Pointer.y == 153 then
screen.print(170,101,"Number of morningstars: " .. morningstar1,black)
end
if Pointer.x == 310 and Pointer.y == 153 then
screen.print(170,101,"Number of spears: " .. spear1,black)
end
if Pointer.x == 339 and Pointer.y == 153 then
screen.print(170,101,"Number of kopeshes: " .. kopesh1,black)
end
if Pointer.x == 368 and Pointer.y == 153 then
screen.print(170,101,"Number of scimitars: " .. scimitar1,black)
end

--Pointer.y == 182 is used a lot here
if Pointer.x == 165 and Pointer.y == 182 then
screen.print(170,101,"Number of cloth suits: " .. cloth1,black)
end
if Pointer.x == 194 and Pointer.y == 182 then
screen.print(170,101,"Number of black suits: " .. black1,black)
end
if Pointer.x == 223 and Pointer.y == 182 then
screen.print(170,101,"Number of holy suits: " .. holy1,black)
end
if Pointer.x == 252 and Pointer.y == 182 then
screen.print(170,101,"Number of steel suits: " .. steel1,black)
end
if Pointer.x == 281 and Pointer.y == 182 then
screen.print(170,101,"Number of leather suits: " .. leather1,black)
end
if Pointer.x == 310 and Pointer.y == 182 then
screen.print(170,101,"Number of mail suits: " .. mail1,black)
end

--Block[1].y == 29 here
if Block1[1].y == 29 then
--As stated above, a bad way to load images
ingameitems = image.load("Images/ingameitems.png")
ingameitems:blit(146,1)
pointer1 = image.load("Images/pointer.png")
pointer1:blit(Pointer1.x,Pointer1.y)
end
if controls.press("right") and Pointer1.x <= 426 and Block1[1].y == 29 then
Pointer1.x = Pointer1.x + 29
end
if controls.press("left") and Pointer1.x >= 194 and Block1[1].y == 29 then
Pointer1.x = Pointer1.x - 29
end
if controls.press("up") and Pointer1.y >= 40 and Block1[1].y == 29 then
Pointer1.y = Pointer1.y - 29
end
if controls.press("down") and Pointer1.y <= 215 and Block1[1].y == 29 then
Pointer1.y = Pointer1.y + 29
end

if Block1[1].y == 48 then

end

if Block1[1].y == 67 then
--Same with the image loading here
blank = image.load("Images/blank.png")
blank:blit(146,1)
if controls.press("cross") then
saved = savegame()
if saved then
os.message("Game saved successfully")
else
os.message("Game could not be saved")
end
end
end

if Block1[1].y == 87 then
blank:blit(146,1)
if controls.press("cross") then
if area == 1 then
dofile("town.lua")
elseif area == 2 then
dofile("enviroment.lua")
end
end
end

if controls.press("r") then
if Block1[1].y == 11 then
Block1[1].y = Block1[1].y + 18
Block1[2].y = Block1[2].y + 18
Block2[1].y = Block2[1].y + 18
Block2[2].y = Block2[2].y + 18
elseif Block1[1].y == 29 then
Block1[1].y = Block1[1].y + 19
Block1[2].y = Block1[2].y + 19
Block2[1].y = Block2[1].y + 19
Block2[2].y = Block2[2].y + 19
elseif Block1[1].y == 48 then
Block1[1].y = Block1[1].y + 19
Block1[2].y = Block1[2].y + 19
Block2[1].y = Block2[1].y + 19
Block2[2].y = Block2[2].y + 19
elseif Block1[1].y == 67 then
Block1[1].y = Block1[1].y + 20
Block1[2].y = Block1[2].y + 20
Block2[1].y = Block2[1].y + 20
Block2[2].y = Block2[2].y + 20
elseif Block1[1].y == 87 then
Block1[1].y = Block1[1].y - 76
Block1[2].y = Block1[2].y - 76
Block2[1].y = Block2[1].y - 76
Block2[2].y = Block2[2].y - 76
end
end

if controls.press("l") then
if Block1[1].y == 11 then
Block1[1].y = Block1[1].y + 76
Block1[2].y = Block1[2].y + 76
Block2[1].y = Block2[1].y + 76
Block2[2].y = Block2[2].y + 76
elseif Block1[1].y == 29 then
Block1[1].y = Block1[1].y - 18
Block1[2].y = Block1[2].y - 18
Block2[1].y = Block2[1].y - 18
Block2[2].y = Block2[2].y - 18
elseif Block1[1].y == 48 then
Block1[1].y = Block1[1].y - 19
Block1[2].y = Block1[2].y - 19
Block2[1].y = Block2[1].y - 19
Block2[2].y = Block2[2].y - 19
elseif Block1[1].y == 67 then
Block1[1].y = Block1[1].y - 19
Block1[2].y = Block1[2].y - 19
Block2[1].y = Block2[1].y - 19
Block2[2].y = Block2[2].y - 19
elseif Block1[1].y == 87 then
Block1[1].y = Block1[1].y - 20
Block1[2].y = Block1[2].y - 20
Block2[1].y = Block2[1].y - 20
Block2[2].y = Block2[2].y - 20
end
end
end

Block1 = {}
Block1[1] = { x = 9, y = 11, height = block1:height(), width = block1:width() }
Block1[2] = { x = 73, y = 11, height = block1:height(), width = block1:width() }

Block2 = {}
Block2[1] = { x = 9, y = 11, height = block2:height(), width = block2:width() }
Block2[2] = { x = 9, y = 26, height = block2:height(), width = block2:width() }

background = image.load("Images/ingameequipment.png")

while true do
screen.clear()
background:blit(0,0)
checkcontrols()
if controls.press("start") then
screenpic("ms0:/PSP/PHOTO")
end
for a = 1,2 do
block1:blit(Block1[a].x,Block1[a].y)
end
for a = 1,2 do
block2:blit(Block2[a].x,Block2[a].y)
end
screen.print(42,251,myCash,black)
--Block[1].y == 11 here
--Here the images will keep on loading too
if weapon == "dagger" and Block1[1].y == 11 then
dagger=image.load("Images/dagger.png")
dagger:blit(204,49)
end
if weapon == "elucidator" and Block1[1].y == 11 then
elucidator=image.load("Images/elucidator.png")
elucidator:blit(204,49)
end
if weapon == "axe" and Block1[1].y == 11 then
axe=image.load("Images/axe.png")
axe:blit(204,49)
end
if weapon == "broadsword" and Block1[1].y == 11 then
broadsword=image.load("Images/broadsword.png")
broadsword:blit(204,49)
end
if weapon == "morningstar" and Block1[1].y == 11 then
morningstar=image.load("Images/morningstar.png")
morningstar:blit(204,49)
end
if weapon == "spear" and Block1[1].y == 11 then
spear=image.load("Images/spear.png")
spear:blit(204,49)
end
if weapon == "scimitar" and Block1[1].y == 11 then
scimitar=image.load("Images/scimitar.png")
scimitar:blit(204,49)
end
if weapon == "kopesh" and Block1[1].y == 11 then
kopesh=image.load("Images/kopesh.png")
kopesh:blit(204,49)
end
screen.waitvblankstart()
screen.flip()
end
[/spoiler]
As you can see in the above code there is a lot of repetitiveness.
What you can do is place all the corresponding code inside one if statement, especially for the controls since it will slow it down if you have a lot of if statements with controls.

Here is the code with the rearrangements and fixes with the loading.
[spoiler]
green = color.new(0, 255, 0)
lgreen = color.new(0,128,0)
white = color.new(255,255,255)
brown = color.new(156,90,60)
red = color.new(255,0,0)
blue = color.new(0,0,255)
black = color.new(0,0,0)
redD = color.new(177,7,12)

block1 = image.create(1,16,redD)

block2 = image.create(65,1,redD)

Pointer = { x = 165, y = 153}

Pointer1 = { x = 165, y = 11}

function checkcontrols()
controls.read()
--Here the statements are wrapped inside one Block1[1].y == 11 statement
if Block1[1].y == 11 then
--Now the image will only be loaded if it has not been loaded already
if not pointer then
pointer = image.load("Images/pointer.png")
end
pointer:blit(Pointer.x,Pointer.y)
if controls.press("right") and Pointer.x <= 368 then
Pointer.x = Pointer.x + 29
end
if controls.press("left") and Pointer.x >= 194 then
Pointer.x = Pointer.x - 29
end
if controls.press("down") and Pointer.y <= 153 then
Pointer.y = Pointer.y + 29
end
if controls.press("up") and Pointer.y >= 182 then
Pointer.y = Pointer.y - 29
end
--Here the statements are wrapped in one controls.press("cross") statement
if controls.press("cross") then
--The same here with Pointer.y == 153
if Pointer.y == 153 then
if Pointer.x == 165 and axe1 >= 1 then
weapon = "axe"
end
if Pointer.x == 194 and broadsword1 >= 1 then
weapon = "broadsword"
end
if Pointer.x == 223 and elucidator1 >= 1 then
weapon = "elucidator"
end
if Pointer.x == 252 and dagger1 >= 1 then
weapon = "dagger"
end
if Pointer.x == 281 and morningstar1 >= 1 then
weapon = "morningstar"
end
if Pointer.x == 310 and spear1 >= 1 then
weapon = "spear"
end
if Pointer.x == 339 and kopesh1 >= 1 then
weapon = "kopesh"
end
if Pointer.x == 368 and scimitar1 >= 1 then
weapon = "scimitar"
end
end
--Pointer.y == 182 here
if Pointer.y == 182 then
if Pointer.x == 165 and cloth1 >= 1 then
armor = "cloth"
end
if Pointer.x == 194 and black1 >= 1 then
armor = "black"
end
if Pointer.x == 223 and holy1 >= 1 then
armor = "holy"
end
if Pointer.x == 252 and steel1 >= 1 then
armor = "steel"
end
if Pointer.x == 281 and leather1 >= 1 then
armor = "leather"
end
if Pointer.x == 310 and mail1 >= 1 then
armor = "mail"
end
end
end
end

--Pointer.y == 153 here
if Pointer.y == 153 then
if Pointer.x == 165 then
screen.print(170,101,"Number of axes: " .. axe1,black)
end
if Pointer.x == 194 then
screen.print(170,101,"Number of broadswords: " .. broadsword1,black)
end
if Pointer.x == 223 then
screen.print(170,101,"Number of elucidators: " .. elucidator1,black)
end
if Pointer.x == 252 then
screen.print(170,101,"Number of daggers: " .. dagger1,black)
end
if Pointer.x == 281 then
screen.print(170,101,"Number of morningstars: " .. morningstar1,black)
end
if Pointer.x == 310 then
screen.print(170,101,"Number of spears: " .. spear1,black)
end
if Pointer.x == 339 then
screen.print(170,101,"Number of kopeshes: " .. kopesh1,black)
end
if Pointer.x == 368 then
screen.print(170,101,"Number of scimitars: " .. scimitar1,black)
end
end

--Pointer.y == 182
if Pointer.y == 182 then
if Pointer.x == 165 then
screen.print(170,101,"Number of cloth suits: " .. cloth1,black)
end
if Pointer.x == 194 then
screen.print(170,101,"Number of black suits: " .. black1,black)
end
if Pointer.x == 223 then
screen.print(170,101,"Number of holy suits: " .. holy1,black)
end
if Pointer.x == 252 then
screen.print(170,101,"Number of steel suits: " .. steel1,black)
end
if Pointer.x == 281 then
screen.print(170,101,"Number of leather suits: " .. leather1,black)
end
if Pointer.x == 310 then
screen.print(170,101,"Number of mail suits: " .. mail1,black)
end
end

--Block1[1].y == 29 here
if Block1[1].y == 29 then
ingameitems = image.load("Images/ingameitems.png")
ingameitems:blit(146,1)
--Load the image once here
if not pointer1 then
pointer1 = image.load("Images/pointer.png")
end
pointer1:blit(Pointer1.x,Pointer1.y)
if controls.press("right") and Pointer1.x <= 426 then
Pointer1.x = Pointer1.x + 29
end
if controls.press("left") and Pointer1.x >= 194 then
Pointer1.x = Pointer1.x - 29
end
if controls.press("up") and Pointer1.y >= 40 then
Pointer1.y = Pointer1.y - 29
end
if controls.press("down") and Pointer1.y <= 215 then
Pointer1.y = Pointer1.y + 29
end
end

if Block1[1].y == 48 then

end

if Block1[1].y == 67 then
--Load image once here too
if not blank then
blank = image.load("Images/blank.png")
end
blank:blit(146,1)
if controls.press("cross") then
saved = savegame()
if saved then
os.message("Game saved successfully")
else
os.message("Game could not be saved")
end
end
end

if Block1[1].y == 87 then
blank:blit(146,1)
if controls.press("cross") then
if area == 1 then
dofile("town.lua")
elseif area == 2 then
dofile("enviroment.lua")
end
end
end

if controls.press("r") then
if Block1[1].y == 11 then
Block1[1].y = Block1[1].y + 18
Block1[2].y = Block1[2].y + 18
Block2[1].y = Block2[1].y + 18
Block2[2].y = Block2[2].y + 18
elseif Block1[1].y == 29 then
Block1[1].y = Block1[1].y + 19
Block1[2].y = Block1[2].y + 19
Block2[1].y = Block2[1].y + 19
Block2[2].y = Block2[2].y + 19
elseif Block1[1].y == 48 then
Block1[1].y = Block1[1].y + 19
Block1[2].y = Block1[2].y + 19
Block2[1].y = Block2[1].y + 19
Block2[2].y = Block2[2].y + 19
elseif Block1[1].y == 67 then
Block1[1].y = Block1[1].y + 20
Block1[2].y = Block1[2].y + 20
Block2[1].y = Block2[1].y + 20
Block2[2].y = Block2[2].y + 20
elseif Block1[1].y == 87 then
Block1[1].y = Block1[1].y - 76
Block1[2].y = Block1[2].y - 76
Block2[1].y = Block2[1].y - 76
Block2[2].y = Block2[2].y - 76
end
end

if controls.press("l") then
if Block1[1].y == 11 then
Block1[1].y = Block1[1].y + 76
Block1[2].y = Block1[2].y + 76
Block2[1].y = Block2[1].y + 76
Block2[2].y = Block2[2].y + 76
elseif Block1[1].y == 29 then
Block1[1].y = Block1[1].y - 18
Block1[2].y = Block1[2].y - 18
Block2[1].y = Block2[1].y - 18
Block2[2].y = Block2[2].y - 18
elseif Block1[1].y == 48 then
Block1[1].y = Block1[1].y - 19
Block1[2].y = Block1[2].y - 19
Block2[1].y = Block2[1].y - 19
Block2[2].y = Block2[2].y - 19
elseif Block1[1].y == 67 then
Block1[1].y = Block1[1].y - 19
Block1[2].y = Block1[2].y - 19
Block2[1].y = Block2[1].y - 19
Block2[2].y = Block2[2].y - 19
elseif Block1[1].y == 87 then
Block1[1].y = Block1[1].y - 20
Block1[2].y = Block1[2].y - 20
Block2[1].y = Block2[1].y - 20
Block2[2].y = Block2[2].y - 20
end
end
end

Block1 = {}
Block1[1] = { x = 9, y = 11, height = block1:height(), width = block1:width() }
Block1[2] = { x = 73, y = 11, height = block1:height(), width = block1:width() }

Block2 = {}
Block2[1] = { x = 9, y = 11, height = block2:height(), width = block2:width() }
Block2[2] = { x = 9, y = 26, height = block2:height(), width = block2:width() }

background = image.load("Images/ingameequipment.png")

while true do
screen.clear()
background:blit(0,0)
checkcontrols()
if controls.press("start") then
screenpic("ms0:/PSP/PHOTO")
end
for a = 1,2 do
block1:blit(Block1[a].x,Block1[a].y)
end
for a = 1,2 do
block2:blit(Block2[a].x,Block2[a].y)
end
screen.print(42,251,myCash,black)
--Block1[1].y == 11 here
if Block1[1].y == 11 then
if weapon == "dagger" then
--Load image once
if not dagger then
dagger=image.load("Images/dagger.png")
end
dagger:blit(204,49)
end
if weapon == "elucidator" then
--Load image once
if not elucidator then
elucidator=image.load("Images/elucidator.png")
end
elucidator:blit(204,49)
end
if weapon == "axe" then
--Load image once
if not axe then
axe=image.load("Images/axe.png")
end
axe:blit(204,49)
end
if weapon == "broadsword" then
--Load image once
if not broadsword then
broadsword=image.load("Images/broadsword.png")
end
broadsword:blit(204,49)
end
if weapon == "morningstar" then
--Load image once
if not morningstar then
morningstar=image.load("Images/morningstar.png")
end
morningstar:blit(204,49)
end
if weapon == "spear" then
--Load image once
if not spear then
spear=image.load("Images/spear.png")
end
spear:blit(204,49)
end
if weapon == "scimitar" then
--Load image once
if not scimitar then
scimitar=image.load("Images/scimitar.png")
end
scimitar:blit(204,49)
end
if weapon == "kopesh" then
--Load image once
if not kopesh then
kopesh=image.load("Images/kopesh.png")
end
kopesh:blit(204,49)
end
end
screen.waitvblankstart()
screen.flip()
end
[/spoiler]
Here's the revised code inside code tags.

Code: Select all

green = color.new(0, 255, 0)
lgreen = color.new(0,128,0)
white = color.new(255,255,255)
brown = color.new(156,90,60)
red = color.new(255,0,0)
blue = color.new(0,0,255)
black = color.new(0,0,0)
redD = color.new(177,7,12)

block1 = image.create(1,16,redD)

block2 = image.create(65,1,redD)

Pointer = { x = 165, y = 153}

Pointer1 = { x = 165, y = 11}

function checkcontrols()
  controls.read()
  --Here the statements are wrapped inside one Block1[1].y == 11 statement
  if Block1[1].y == 11 then
    --Now the image will only be loaded if it has not been loaded already
    if not pointer then
      pointer = image.load("Images/pointer.png")
    end
    pointer:blit(Pointer.x,Pointer.y)
    if controls.press("right") and Pointer.x <= 368 then
      Pointer.x = Pointer.x + 29
    end
    if controls.press("left") and Pointer.x >= 194 then
      Pointer.x = Pointer.x - 29
    end
    if controls.press("down") and Pointer.y <= 153 then
      Pointer.y = Pointer.y + 29
    end
    if controls.press("up") and Pointer.y >= 182 then
      Pointer.y = Pointer.y - 29
    end
    --Here the statements are wrapped in one controls.press("cross") statement
    if controls.press("cross") then
    --The same here with Pointer.y == 153
      if Pointer.y == 153 then
        if Pointer.x == 165 and axe1 >= 1 then
          weapon = "axe"
        end
        if Pointer.x == 194 and broadsword1 >= 1 then
          weapon = "broadsword"
        end
        if Pointer.x == 223 and elucidator1 >= 1 then
          weapon = "elucidator"
        end
        if Pointer.x == 252 and dagger1 >= 1 then
          weapon = "dagger"
        end
        if Pointer.x == 281 and morningstar1 >= 1 then
          weapon = "morningstar"
        end
        if Pointer.x == 310 and spear1 >= 1 then
          weapon = "spear"
        end
        if Pointer.x == 339 and kopesh1 >= 1 then
          weapon = "kopesh"
        end
        if Pointer.x == 368 and scimitar1 >= 1 then
          weapon = "scimitar"
        end
      end
      --Pointer.y == 182 here
      if Pointer.y == 182 then
        if Pointer.x == 165 and cloth1 >= 1 then
          armor = "cloth"
        end
        if Pointer.x == 194 and black1 >= 1 then
          armor = "black"
        end
        if Pointer.x == 223 and holy1 >= 1 then
          armor = "holy"
        end
        if Pointer.x == 252 and steel1 >= 1 then
          armor = "steel"
        end
        if Pointer.x == 281 and leather1 >= 1 then
          armor = "leather"
        end
        if Pointer.x == 310 and mail1 >= 1 then
          armor = "mail"
        end
      end
    end
  end

  --Pointer.y == 153 here
  if Pointer.y == 153 then
    if Pointer.x == 165 then
      screen.print(170,101,"Number of axes: " .. axe1,black)
    end
    if Pointer.x == 194 then
      screen.print(170,101,"Number of broadswords: " .. broadsword1,black)
    end
    if Pointer.x == 223 then
      screen.print(170,101,"Number of elucidators: " .. elucidator1,black)
    end
    if Pointer.x == 252 then
      screen.print(170,101,"Number of daggers: " .. dagger1,black)
    end
    if Pointer.x == 281 then
      screen.print(170,101,"Number of morningstars: " .. morningstar1,black)
    end
    if Pointer.x == 310 then
      screen.print(170,101,"Number of spears: " .. spear1,black)
    end
    if Pointer.x == 339 then
      screen.print(170,101,"Number of kopeshes: " .. kopesh1,black)
    end
    if Pointer.x == 368 then
      screen.print(170,101,"Number of scimitars: " .. scimitar1,black)
    end
  end

  --Pointer.y == 182
  if Pointer.y == 182 then
    if Pointer.x == 165 then
      screen.print(170,101,"Number of cloth suits: " .. cloth1,black)
    end
    if Pointer.x == 194 then
      screen.print(170,101,"Number of black suits: " .. black1,black)
    end
    if Pointer.x == 223 then
      screen.print(170,101,"Number of holy suits: " .. holy1,black)
    end
    if Pointer.x == 252 then
      screen.print(170,101,"Number of steel suits: " .. steel1,black)
    end
    if Pointer.x == 281 then
      screen.print(170,101,"Number of leather suits: " .. leather1,black)
    end
    if Pointer.x == 310 then
      screen.print(170,101,"Number of mail suits: " .. mail1,black)
    end
  end

  --Block1[1].y == 29 here
  if Block1[1].y == 29 then
    ingameitems = image.load("Images/ingameitems.png")
    ingameitems:blit(146,1)
    --Load the image once here
    if not pointer1 then
      pointer1 = image.load("Images/pointer.png")
    end
    pointer1:blit(Pointer1.x,Pointer1.y)
    if controls.press("right") and Pointer1.x <= 426 then
      Pointer1.x = Pointer1.x + 29
    end
    if controls.press("left") and Pointer1.x >= 194 then
      Pointer1.x = Pointer1.x - 29
    end
    if controls.press("up") and Pointer1.y >= 40 then
      Pointer1.y = Pointer1.y - 29
    end
    if controls.press("down") and Pointer1.y <= 215 then
      Pointer1.y = Pointer1.y + 29
    end
  end

  if Block1[1].y == 48 then
    
  end

  if Block1[1].y == 67 then
    --Load image once here too
    if not blank then
      blank = image.load("Images/blank.png")
    end
    blank:blit(146,1)
    if controls.press("cross") then
      saved = savegame()
      if saved then
        os.message("Game saved successfully")
      else
        os.message("Game could not be saved")
      end
    end
  end

  if Block1[1].y == 87 then
    blank:blit(146,1)
    if controls.press("cross") then
      if area == 1 then
        dofile("town.lua")
      elseif area == 2 then
        dofile("enviroment.lua")
      end
    end
  end

  if controls.press("r") then
    if Block1[1].y == 11 then
      Block1[1].y = Block1[1].y + 18
      Block1[2].y = Block1[2].y + 18
      Block2[1].y = Block2[1].y + 18
      Block2[2].y = Block2[2].y + 18
    elseif Block1[1].y == 29 then
      Block1[1].y = Block1[1].y + 19
      Block1[2].y = Block1[2].y + 19
      Block2[1].y = Block2[1].y + 19
      Block2[2].y = Block2[2].y + 19
    elseif Block1[1].y == 48 then
      Block1[1].y = Block1[1].y + 19
      Block1[2].y = Block1[2].y + 19
      Block2[1].y = Block2[1].y + 19
      Block2[2].y = Block2[2].y + 19
    elseif Block1[1].y == 67 then
      Block1[1].y = Block1[1].y + 20
      Block1[2].y = Block1[2].y + 20
      Block2[1].y = Block2[1].y + 20
      Block2[2].y = Block2[2].y + 20
    elseif Block1[1].y == 87 then
      Block1[1].y = Block1[1].y - 76
      Block1[2].y = Block1[2].y - 76
      Block2[1].y = Block2[1].y - 76
      Block2[2].y = Block2[2].y - 76
    end
  end

  if controls.press("l") then
    if Block1[1].y == 11 then
      Block1[1].y = Block1[1].y + 76
      Block1[2].y = Block1[2].y + 76
      Block2[1].y = Block2[1].y + 76
      Block2[2].y = Block2[2].y + 76
    elseif Block1[1].y == 29 then
      Block1[1].y = Block1[1].y - 18
      Block1[2].y = Block1[2].y - 18
      Block2[1].y = Block2[1].y - 18
      Block2[2].y = Block2[2].y - 18
    elseif Block1[1].y == 48 then
      Block1[1].y = Block1[1].y - 19
      Block1[2].y = Block1[2].y - 19
      Block2[1].y = Block2[1].y - 19
      Block2[2].y = Block2[2].y - 19
    elseif Block1[1].y == 67 then
      Block1[1].y = Block1[1].y - 19
      Block1[2].y = Block1[2].y - 19
      Block2[1].y = Block2[1].y - 19
      Block2[2].y = Block2[2].y - 19
    elseif Block1[1].y == 87 then
      Block1[1].y = Block1[1].y - 20
      Block1[2].y = Block1[2].y - 20
      Block2[1].y = Block2[1].y - 20
      Block2[2].y = Block2[2].y - 20
    end
  end
end

Block1 = {}
Block1[1] = { x = 9, y = 11, height = block1:height(), width = block1:width() }
Block1[2] = { x = 73, y = 11, height = block1:height(), width = block1:width() }

Block2 = {}
Block2[1] = { x = 9, y = 11, height = block2:height(), width = block2:width() }
Block2[2] = { x = 9, y = 26, height = block2:height(), width = block2:width() }

background = image.load("Images/ingameequipment.png")

while true do
  screen.clear()
  background:blit(0,0)
  checkcontrols()
  if controls.press("start") then
    screenpic("ms0:/PSP/PHOTO")
  end
  for a = 1,2 do
    block1:blit(Block1[a].x,Block1[a].y)
  end
  for a = 1,2 do
    block2:blit(Block2[a].x,Block2[a].y)
  end
  screen.print(42,251,myCash,black)
  --Block1[1].y == 11 here
  if Block1[1].y == 11 then
    if weapon == "dagger" then
      --Load image once
      if not dagger then
        dagger=image.load("Images/dagger.png")
      end
      dagger:blit(204,49)
    end
    if weapon == "elucidator" then
      --Load image once
      if not elucidator then
        elucidator=image.load("Images/elucidator.png")
      end
      elucidator:blit(204,49)
    end
    if weapon == "axe" then
      --Load image once
      if not axe then
        axe=image.load("Images/axe.png")
      end
      axe:blit(204,49)
    end
    if weapon == "broadsword" then
      --Load image once
      if not broadsword then
        broadsword=image.load("Images/broadsword.png")
      end
      broadsword:blit(204,49)
    end
    if weapon == "morningstar" then
      --Load image once
      if not morningstar then
        morningstar=image.load("Images/morningstar.png")
      end
      morningstar:blit(204,49)
    end
    if weapon == "spear" then
      --Load image once
      if not spear then
        spear=image.load("Images/spear.png")
      end
      spear:blit(204,49)
    end
    if weapon == "scimitar" then
      --Load image once
      if not scimitar then
        scimitar=image.load("Images/scimitar.png")
      end
      scimitar:blit(204,49)
    end
    if weapon == "kopesh" then
      --Load image once
      if not kopesh then
        kopesh=image.load("Images/kopesh.png")
      end
      kopesh:blit(204,49)
    end
  end
  screen.waitvblankstart()
  screen.flip()
end
The non-stop image loading is the reason why the memory stick indicator kept on flashing when playing the game, this revision should fix that problem.
It would be a good idea to look at the rest of your code and look for similar problems.

I haven't figured out why the game loading isn't working as it should, have you saved after running town.lua?
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

Yes I save after running town. lua, I'm thinking you have the load after town. lua, maybe you could download my game and try. Also thanks the image loading was a problem for my psp dice game as well but I didn't know that till now.
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

I'm going to stay up all of tonight have you found out why the saving/loading inserted in my code isn't working? I actually found out that some of my code is redundant and have been fixing it. I'm planning on adding text saying what each building is when you step in the door, adding prices of items, and armor picture.
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 »

dragonxtamer596 wrote:I'm going to stay up all of tonight have you found out why the saving/loading inserted in my code isn't working? I actually found out that some of my code is redundant and have been fixing it. I'm planning on adding text saying what each building is when you step in the door, adding prices of items, and armor picture.
Can you send me the latest code?
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

qwikrazor87 wrote:
dragonxtamer596 wrote:I'm going to stay up all of tonight have you found out why the saving/loading inserted in my code isn't working? I actually found out that some of my code is redundant and have been fixing it. I'm planning on adding text saying what each building is when you step in the door, adding prices of items, and armor picture.
Can you send me the latest code?
Ok let me clean the rest of the attributes menu up.
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

I get this random error every once in a while it has something to do with chunks. Do you know how to fix it (I'll play my game again and see what the error completely says). I'm surprised that I don't have any more errors besides the save and loading which I'm going to keep messing with.
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 »

I've been busy and not working on my game lately but I came back and I forgot how to make a not statement work.
My goal is to make the character go in only one direction at a time. It worked to stop diagonal in the direction pushed but if a player does try example left and down he will go up right. What is going on here?
This is what I tried \/

Code: Select all

     if controls.left() ~= (controls.up() or controls.down())  then
       Player.x = Player.x - 1.25
     end
     if controls.right() ~= (controls.up() or controls.down()) then
       Player.x = Player.x + 1.25
     end
     if controls.up() ~= (controls.left() or controls.right()) then
       Player.y = Player.y - 1.25
     end
     if controls.down() ~= (controls.left() or controls.right()) then
       Player.y = Player.y + 1.25
     end
Locked

Return to “Programming and Security”