FAQ  •  Register  •  Login

Opposite forces

<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Tue Apr 01, 2014 8:29 pm

Opposite forces

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
Last edited by tazinator on Tue Apr 01, 2014 8:53 pm, edited 1 time in total.
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

raptor

Posts: 1046

Joined: Mon Oct 11, 2010 9:03 pm

Post Tue Apr 01, 2014 8:33 pm

Re: Opposite forces

use '=='

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

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

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Tue Apr 01, 2014 9:16 pm

Re: Opposite forces

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.
Last edited by tazinator on Tue Apr 01, 2014 9:19 pm, edited 1 time in total.
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

Fordcars

User avatar

Posts: 1016

Joined: Fri Apr 20, 2012 3:51 pm

Location: Some city, somewhere

Post Tue Apr 01, 2014 9:17 pm

Re: Opposite forces

A ')' is missing!
skybax: Why is this health pack following me?
bobdaduck: uh, it likes you.
<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Tue Apr 01, 2014 9:20 pm

Re: Opposite forces

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
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Tue Apr 01, 2014 9:23 pm

Re: Opposite forces

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
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Tue Apr 01, 2014 11:46 pm

Re: Opposite forces

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
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002

Return to Levelgen Gallery

Who is online

Users browsing this forum: No registered users and 1 guest

cron