Page 1 of 1

Opposite forces

PostPosted: Tue Apr 01, 2014 8:29 pm
by tazinator
this levelgen moves teams in opposite directions
but I can't get the = sign to work in line 23 (and others) for some reason

  Code:
--if Team , then go + score!
--if team , then go - score!
--this will move them in opposite directions..

function main()
    subscribe(Event.Tick);
    for i=1,50 do
        logprint("");
    end
    score = 2
end

function onTick(delta)
  local results = {};
    bf:findAllObjects(results, ObjType.Ship);
        for i,item in ipairs(results) do
    local team = item:getTeamIndex()


    local vel = item:getVel();

--do
if(team = 1) then
      if(vel.x < 600) then
        xvel = vel.x + score
        else
        xvel = vel.x
        end
      if(vel.y < 600) then
        yvel = vel.y + score
        else
        yvel = vel.y
        end
    item:setVel(point.new(xvel, yvel)) 
end
--now do
if(team = 2) then
    xvel = vel.x
    yvel = vel.y
      if(vel.x > -600) then
        xvel = vel.x - score
        else
        xvel = vel.x
        end
      if(vel.y > -600) then
        yvel = vel.y - score
        else
        yvel = vel.y
        end
    item:setVel(point.new(xvel, yvel)) 

    end
end

Re: Opposite forces

PostPosted: Tue Apr 01, 2014 8:33 pm
by raptor
use '=='

== ... this means 'equals'
= ... this means 'assign'

http://www.lua.org/manual/5.1/manual.html#2.5.1

Re: Opposite forces

PostPosted: Tue Apr 01, 2014 9:16 pm
by tazinator
ok,
if(team==1) then


but it is still saying
moveit.levelgen:23: ')' expected near '='

i think it's the for loop. If I move around lines before and after line 23, it does not change that what it says. If I delete line 23, it STILL says this.

Re: Opposite forces

PostPosted: Tue Apr 01, 2014 9:17 pm
by Fordcars
A ')' is missing!

Re: Opposite forces

PostPosted: Tue Apr 01, 2014 9:20 pm
by tazinator
EDIT WOW IT'S THE WRONG LEVELGEN
I was editing a levelgen on my desktop instead of the one in the levels folder.. sorry guys

Re: Opposite forces

PostPosted: Tue Apr 01, 2014 9:23 pm
by tazinator
here's the next version. still not working, but it outputs no errors, either.

  Code:
--if Team , then go + score!
--if team , then go - score!
--this will move them in opposite directions..

function main()
    subscribe(Event.Tick);
    for i=1,50 do
        logprint("");
    end
    score = 2
end

function onTick(delta)
  local results = {};
    bf:findAllObjects(results, ObjType.Ship);
        for i,item in ipairs(results) do
    local team = item:getTeamIndex()


    local vel = item:getVel();

--do
if(team == 1) then
    xvel = vel.x
    yvel = vel.y
      if(vel.x < 600) then
        xvel = vel.x + score
        else
        xvel = vel.x
        end
      if(vel.y < 600) then
        yvel = vel.y + score
        else
        yvel = vel.y
        end
    item:setVel(point.new(xvel, yvel)) 
end
--now do
if(team == 2) then
    xvel = vel.x
    yvel = vel.y
      if(vel.x > -600) then
        xvel = vel.x - score
        else
        xvel = vel.x
        end
      if(vel.y > -600) then
        yvel = vel.y - score
        else
        yvel = vel.y
        end
    item:setVel(point.new(xvel, yvel)) 

            end --for loop
    end
end

Re: Opposite forces

PostPosted: Tue Apr 01, 2014 11:46 pm
by tazinator
oooh, looks like player ships cannot be affected with velocity the same way other objects are, which totally changes what I was doing.. but anyway, here.

working code.. raptor, are you seeing?
  Code:
--if Team , then go + score!
--if team , then go - score!
--this will move them in opposite directions..

function main()
    subscribe(Event.Tick);
    for i=1,50 do
        logprint("");
    end
end

function onTick(delta)
  local results = {};
    bf:findAllObjects(results, ObjType.Ship, ObjType.SoccerBallItem);
      for i,item in ipairs(results) do
    local team = item:getTeamIndex()
    local vel = item:getVel();
--do
        if(team == 1) then
          item:setVel(point.new(vel.x + .1, vel.x + .1))
        elseif(team == 2) then
          item:setVel(point.new(vel.x - .1, vel.x - .1))
        else
          item:setVel(point.new(vel.x + .1, vel.x + .1))
        end --ifelseif
    end --for
end --function

 

strangely, you can go either northwest or southeast with this levelgen. Not the expected outcome, as on team 1 you should only be finding it smooth going southeast

also..

  Code:
--if Team , then go + score!
--if team , then go - score!
--this will move them in opposite directions..

function main()
    subscribe(Event.Tick);
    for i=1,50 do
        logprint("");
    end
end

function onTick(delta)
  local results = {};
    bf:findAllObjects(results, ObjType.SoccerBallItem, ObjType.TestItem);
        for i,item in ipairs(results) do
    local team = item:getTeamIndex()


    local vel = item:getVel();

--do
        local xvel = vel.x
        local yvel = vel.y
    item:setVel(point.new(vel.x + .1, vel.x + .1))
    end
end


Doing it on Crossing - Rabbit version. the testitems are going craaazy