Toribash
Originally Posted by Blam View Post
anyway HALP.
Look at the bold section (_draw_buttons)
It gets to the echo(#Buttons) but doesnt go further... why?

You used FForms[Buttons[i]] instead of FForms[Buttons[i].formid] in the draw_quad statements.

BTW the I think Forms.lua is a great idea. Keep up the good work.

dofile("Forms.lua")

BID = 0
Buttons = {x = 0, y = 0, w = 0, h = 0, label = "", formid = 0, bid = 0}

function hit_test(hitx,hity,x,y,w,h)
    X1 = x
    X2 = x+w
    Y1 = y
    Y2 = y+h
    if(hitx > X1 and hitx < X2) and (hity > Y1 and hity < Y2) then
        return 1
    else
        return 0
    end
end

function new_button(x,y,w,h,label,formid)
    BID = BID + 1
    Buttons[BID] = {x = 0, y = 0, w = 0, h = 0, label = "", formid = 0}
    Buttons[BID].x = x
    Buttons[BID].y = y
    Buttons[BID].w = w
    Buttons[BID].h = h
    Buttons[BID].label = label
    Buttons[BID].formid = formid
    Buttons[BID].bid = BID
    echo("Button ID:" .. BID)
    echo(Buttons[BID].x .. Buttons[BID].y .. Buttons[BID].w .. Buttons[BID].h .. Buttons[BID].label .. Buttons[BID].formid .. Buttons[BID].bid)
end

function setup()
    new_form(100,100,230,500,"Test Box 1","",1) -- ID = 1
    new_form(0,0,300,500,"Help","",0) -- ID = 2
    new_button(20,20,40,20,"Test",1)
    new_button(20,20,50,20,"Test 2",2)
end

setup()

local function _drawbuttons()
    echo(#Buttons)
    for i=1,#Buttons do
    echo(FForms[Buttons[i].formid].show == 1)
        if(FForms[Buttons[i].formid].show == 1) then
        --Draw Body
        set_color(0.3,1,1,1)
		draw_quad(Buttons[i].x+FForms[Buttons[i].formid].x-2,FForms[Buttons[i].formid].y+Buttons[i].y-2,Buttons[i].w, Buttons[i].h)
        --Draw Bevel Shadow
        set_color(0,0,0,0.1)
		draw_quad(Buttons[i].x+FForms[Buttons[i].formid].x+2,FForms[Buttons[i].formid].y+Buttons[i].y+2,Buttons[i].w-2, Buttons[i].h-2)
        --Draw Bevel Highlight
        set_color(1,1,1,0.1)
		draw_quad(Buttons[i].x+FForms[Buttons[i].formid].x,FForms[Buttons[i].formid].y+Buttons[i].y,Buttons[i].w, Buttons[i].h)
    end
end
end

add_hook("draw2d","FFormsButtons", _drawbuttons)
Originally Posted by Nuyashaki View Post
Sorry, but what is a hook? What does it do and what is it for?

Look at this page for more information http://wiki.toribash.com/index.php?t..._Documentation

Basically a hook is a way of getting toribash to call your code when a certain event occurs. For example the "new_game" hook is called every time a new single player game starts. The best way to understand it is probably to read the wiki and to look at other peoples scripts to see how they use hooks. It should become pretty much self-explanatory then.
Originally Posted by flamflim View Post
You used FForms[Buttons[i]] instead of FForms[Buttons[i].formid] in the draw_quad statements.

BTW the I think Forms.lua is a great idea. Keep up the good work.

dofile("Forms.lua")

BID = 0
Buttons = {x = 0, y = 0, w = 0, h = 0, label = "", formid = 0, bid = 0}

function hit_test(hitx,hity,x,y,w,h)
    X1 = x
    X2 = x+w
    Y1 = y
    Y2 = y+h
    if(hitx > X1 and hitx < X2) and (hity > Y1 and hity < Y2) then
        return 1
    else
        return 0
    end
end

function new_button(x,y,w,h,label,formid)
    BID = BID + 1
    Buttons[BID] = {x = 0, y = 0, w = 0, h = 0, label = "", formid = 0}
    Buttons[BID].x = x
    Buttons[BID].y = y
    Buttons[BID].w = w
    Buttons[BID].h = h
    Buttons[BID].label = label
    Buttons[BID].formid = formid
    Buttons[BID].bid = BID
    echo("Button ID:" .. BID)
    echo(Buttons[BID].x .. Buttons[BID].y .. Buttons[BID].w .. Buttons[BID].h .. Buttons[BID].label .. Buttons[BID].formid .. Buttons[BID].bid)
end

function setup()
    new_form(100,100,230,500,"Test Box 1","",1) -- ID = 1
    new_form(0,0,300,500,"Help","",0) -- ID = 2
    new_button(20,20,40,20,"Test",1)
    new_button(20,20,50,20,"Test 2",2)
end

setup()

local function _drawbuttons()
    echo(#Buttons)
    for i=1,#Buttons do
    echo(FForms[Buttons[i].formid].show == 1)
        if(FForms[Buttons[i].formid].show == 1) then
        --Draw Body
        set_color(0.3,1,1,1)
        draw_quad(Buttons[i].x+FForms[Buttons[i].formid].x-2,FForms[Buttons[i].formid].y+Buttons[i].y-2,Buttons[i].w, Buttons[i].h)
        --Draw Bevel Shadow
        set_color(0,0,0,0.1)
        draw_quad(Buttons[i].x+FForms[Buttons[i].formid].x+2,FForms[Buttons[i].formid].y+Buttons[i].y+2,Buttons[i].w-2, Buttons[i].h-2)
        --Draw Bevel Highlight
        set_color(1,1,1,0.1)
        draw_quad(Buttons[i].x+FForms[Buttons[i].formid].x,FForms[Buttons[i].formid].y+Buttons[i].y,Buttons[i].w, Buttons[i].h)
    end
end
end

add_hook("draw2d","FFormsButtons", _drawbuttons)

Oh yeah thanks *facepalms self again*
:D
I need help with a script I made from pummel2 and countervector. It works with version 3.06, but not 3.1. It'll crash after like, 3 seconds of play, and when it does, it'll display a score of -1. I'm at school right now (3.06), and I've been running it for about 15 min now, and nothing is wrong with it. But at home (3.1) it crashes. Why?
pummel = {}
local ukeposx = { }
local ukeposy = { }
local ukeposz = { }
pummel.thrust = 8
pummel.damage = get_player_info(0).score
pummel.hitter = 11
pummel.counter = 0
function rollTarget()
  --[[
  local tmp
  while(true) do
    tmp = math.random(0, 18)
    if(tmp~=11 and tmp~=12) then break end
  end
  return tmp
  ]]--
  return 0
end
pummel.target1 = rollTarget()
pummel.target2 = rollTarget()
function unitize(vector)
  mag = math.sqrt(vector.x*vector.x + vector.y*vector.y + vector.z*vector.z)
  return {x=vector.x/mag, y=vector.y/mag, z=vector.z/mag}
end
function applyThrust()
  pummel.counter = pummel.counter + 1
  set_joint_state(0, 6, 2)
  set_joint_state(0, 9, 2)
  set_joint_state(0, 10, 1)
  set_joint_state(0, 11, 1)
  set_joint_state(0, 4, 1)
  set_joint_state(0, 7, 1)
  pummel.target1Pos = get_body_info(1, pummel.target1).pos
  pummel.target2Pos = get_body_info(1, pummel.target2).pos
 
  if(pummel.counter % 25 == 0) then
    pummel.counter = 0
    if(pummel.hitter == 11) then
      pummel.target2 = rollTarget()
      pummel.hitter = 12
    else
      pummel.target1 = rollTarget()
      pummel.hitter = 11
    end
  else
    rhandPos = get_body_info(0, 11).pos
    lhandPos = get_body_info(0, 12).pos
    local force1 = unitize({x=pummel.target1Pos.x-rhandPos.x, y=pummel.target1Pos.y-rhandPos.y, z=pummel.target1Pos.z-rhandPos.z})
    local force2 = unitize({x=pummel.target2Pos.x-lhandPos.x, y=pummel.target2Pos.y-lhandPos.y, z=pummel.target2Pos.z-lhandPos.z})
    if(pummel.hitter == 11) then
      set_body_force(0, 11, force1.x*pummel.thrust, force1.y*pummel.thrust, force1.z*pummel.thrust)
      set_body_force(0, 12, -force2.x*pummel.thrust/2, -force2.y*pummel.thrust/2, -force2.z*pummel.thrust/2)
    else
      set_body_force(0, 11, -force1.x*pummel.thrust/2, -force1.y*pummel.thrust/2, -force1.z*pummel.thrust/2)
      set_body_force(0, 12, force2.x*pummel.thrust, force2.y*pummel.thrust, force2.z*pummel.thrust)
    end
  end
end
function move()
 for b=0,20 do
  local p = get_body_info(1,b).pos
  local v = { }
  v.x = ukeposx[b] - p.x
  v.y = ukeposy[b] - p.y
  v.z = ukeposz[b] - p.z
 
  set_body_force(1, b, v.x*125, v.y*125, v.z*125)
 end
end
function init()
 for b=0,20 do
  local p = get_body_info(1,b).pos
 
  ukeposx[b], ukeposy[b], ukeposz[b] = p.x, p.y, p.z
 end
end
function start()
  pummel.damage = get_player_info(0).score
end
add_hook("enter_frame","countervector",move)
add_hook("new_game","countervector",init)
add_hook("enter_frame","pummel", applyThrust)
add_hook("new_game","pummel", start)
Last edited by Nuyashaki; Feb 15, 2008 at 07:16 PM.
Originally Posted by Nuyashaki View Post
I need help with a script I made from pummel2 and countervector. It works with version 3.06, but not 3.1. It'll crash after like, 3 seconds of play, and when it does, it'll display a score of -1. I'm at school right now (3.06), and I've been running it for about 15 min now, and nothing is wrong with it. But at home (3.1) it crashes. Why?

Well I think I've fixed it, but I don't know how. I changed ukepos to not be local, to help with debugging and this seams to have fixed the problem.

pummel = {}
ukeposx = { }
ukeposy = { }
ukeposz = { }
pummel.thrust = 8
pummel.damage = get_player_info(0).score
pummel.hitter = 11
pummel.counter = 0
function rollTarget()
  --[[
  local tmp
  while(true) do
    tmp = math.random(0, 18)
    if(tmp~=11 and tmp~=12) then break end
  end
  return tmp
  ]]--
  return 0
end
pummel.target1 = rollTarget()
pummel.target2 = rollTarget()
function unitize(vector)
  mag = math.sqrt(vector.x*vector.x + vector.y*vector.y + vector.z*vector.z)
  return {x=vector.x/mag, y=vector.y/mag, z=vector.z/mag}
end
function applyThrust()
  pummel.counter = pummel.counter + 1
  set_joint_state(0, 6, 2)
  set_joint_state(0, 9, 2)
  set_joint_state(0, 10, 1)
  set_joint_state(0, 11, 1)
  set_joint_state(0, 4, 1)
  set_joint_state(0, 7, 1)
  pummel.target1Pos = get_body_info(1, pummel.target1).pos
  pummel.target2Pos = get_body_info(1, pummel.target2).pos
 
  if(pummel.counter % 25 == 0) then
    pummel.counter = 0
    if(pummel.hitter == 11) then
      pummel.target2 = rollTarget()
      pummel.hitter = 12
    else
      pummel.target1 = rollTarget()
      pummel.hitter = 11
    end
  else
    rhandPos = get_body_info(0, 11).pos
    lhandPos = get_body_info(0, 12).pos
    local force1 = unitize({x=pummel.target1Pos.x-rhandPos.x, y=pummel.target1Pos.y-rhandPos.y, z=pummel.target1Pos.z-rhandPos.z})
    local force2 = unitize({x=pummel.target2Pos.x-lhandPos.x, y=pummel.target2Pos.y-lhandPos.y, z=pummel.target2Pos.z-lhandPos.z})
    if(pummel.hitter == 11) then
      set_body_force(0, 11, force1.x*pummel.thrust, force1.y*pummel.thrust, force1.z*pummel.thrust)
      set_body_force(0, 12, -force2.x*pummel.thrust/2, -force2.y*pummel.thrust/2, -force2.z*pummel.thrust/2)
    else
      set_body_force(0, 11, -force1.x*pummel.thrust/2, -force1.y*pummel.thrust/2, -force1.z*pummel.thrust/2)
      set_body_force(0, 12, force2.x*pummel.thrust, force2.y*pummel.thrust, force2.z*pummel.thrust)
    end
  end
end
function move()
 for b=0,20 do
  local p = get_body_info(1,b).pos
  local v = { }
  v.x = ukeposx[b] - p.x
  v.y = ukeposy[b] - p.y
  v.z = ukeposz[b] - p.z
 
  set_body_force(1, b, v.x*125, v.y*125, v.z*125)
 end
end
function init()
 for b=0,20 do
  local p = get_body_info(1,b).pos
 
  ukeposx[b], ukeposy[b], ukeposz[b] = p.x, p.y, p.z
 end
end
function start()
  pummel.damage = get_player_info(0).score
end
add_hook("enter_frame","countervector",move)
add_hook("new_game","countervector",init)
add_hook("enter_frame","pummel", applyThrust)
add_hook("new_game","pummel", start)
function loadshader()
    shaderin = io.open("editshader.inc","r")
    Llist = {}
    line = shaderin:read("*l")
    r1 = 1
    r2 = 1
    for i=1,16 do
        line = shaderin:read("*l")
        Llist[i] = line
    end
    for i=1,5 do
        r1 = string.find(Llist[i]," ",1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].a = tonumber(string.sub(Llist[i],r1,r2))
        r1 = string.find(Llist[i]," ",r2+1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].b = tonumber(string.sub(Llist[i],r1,r2))
        r1 = string.find(Llist[i]," ",r2+1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].c = tonumber(string.sub(Llist[i],r1,r2))
        echo(Llist[i])
        echo(ShaderValues[i].a .. ShaderValues[i].b .. ShaderValues[i].c)
    end
    for i=6,8 do
        r1 = string.find(Llist[i]," ",1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].a = tonumber(string.sub(Llist[i],r1,r2))
        echo(Llist[i])
        echo(ShaderValues[i].a)
    end
    for i=9,16 do
        r1 = string.find(Llist[i]," ",1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].a = tonumber(string.sub(Llist[i],r1,r2))
        r1 = string.find(Llist[i]," ",r2+1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].b = tonumber(string.sub(Llist[i],r1,r2))
        r1 = string.find(Llist[i]," ",r2+1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].c = tonumber(string.sub(Llist[i],r1,r2))
    end
    shaderin:close()
end
Error:
Lua script error: data/script/ShaderMixer.lua:170: attempt to perform arithmetic on global 'r2' (a nil value)

Although r2 isnt a nil value
>.>
<.<
:D
How the hell did you figure that out? What gave you that message?! I WANT IT!

I see r2 up there plenty of times. And it says right there r2 = 1. What the hell?

Thank you flamflim.
Last edited by Nuyashaki; Feb 15, 2008 at 07:01 PM.
Error messages are printed in stderr.txt
Last edited by Blam; Feb 15, 2008 at 07:08 PM. Reason: typo
:D
Originally Posted by Blam View Post
function loadshader()
    shaderin = io.open("editshader.inc","r")
    Llist = {}
    line = shaderin:read("*l")
    r1 = 1
    r2 = 1
    for i=1,16 do
        line = shaderin:read("*l")
        Llist[i] = line
    end
    for i=1,5 do
        r1 = string.find(Llist[i]," ",1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].a = tonumber(string.sub(Llist[i],r1,r2))
        r1 = string.find(Llist[i]," ",r2+1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].b = tonumber(string.sub(Llist[i],r1,r2))
        r1 = string.find(Llist[i]," ",r2+1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].c = tonumber(string.sub(Llist[i],r1,r2))
        echo(Llist[i])
        echo(ShaderValues[i].a .. ShaderValues[i].b .. ShaderValues[i].c)
    end
    for i=6,8 do
        r1 = string.find(Llist[i]," ",1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].a = tonumber(string.sub(Llist[i],r1,r2))
        echo(Llist[i])
        echo(ShaderValues[i].a)
    end
    for i=9,16 do
        r1 = string.find(Llist[i]," ",1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].a = tonumber(string.sub(Llist[i],r1,r2))
        r1 = string.find(Llist[i]," ",r2+1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].b = tonumber(string.sub(Llist[i],r1,r2))
        r1 = string.find(Llist[i]," ",r2+1,true)
        r2 = string.find(Llist[i]," ",r1+1,true)
        ShaderValues[i].c = tonumber(string.sub(Llist[i],r1,r2))
    end
    shaderin:close()
end
Error:
Although r2 isnt a nil value
>.>
<.<

Which line is 170? Make sure you didn't turn it nil.
Radioactive torso's description should be, "You have cancer like wow."