Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How do you return a vector2f from a function.  (Read 3140 times)

0 Members and 1 Guest are viewing this topic.

Aerine

  • Newbie
  • *
  • Posts: 10
    • View Profile
How do you return a vector2f from a function.
« on: April 24, 2017, 12:42:11 am »
So im trying to return a vector2f from a function. So i can use it in a function in another class that takes a vector2f.


if i have the function

template <typename t, typename u>
        sf::Vector2f checkDirection(std::vector<t>  &vtower, std::vector<u>  &vmonster)
        {
                for (int i = 0; i < vmonster.size(); i++)
                {
                        for (int k = 0; k < vtower.size(); k++)
                        {
                                if (vmonster[i].getPositionX() + vmonster[i].getRadius() + vtower[k].getRadius() > vtower[k].getTowerRangePositionX()
                                        && vmonster[i].getPositionX() < vtower[k].getTowerRangePositionX() + vmonster[i].getRadius() + vtower[k].getRadius()
                                        && vmonster[i].getPositionY() + vmonster[i].getRadius() + vtower[k].getRadius() > vtower[k].getTowerRangePositionY()
                                        && vmonster[i].getPositionY() < vtower[k].getTowerRangePositionY() + vmonster[i].getRadius() + vtower[k].getRadius())
                                {
                                        return direction(vmonster[i].getPositionX(), vmonster[i].getPositionY());
                                       
                                       
                                }

                        }
                }
        }

Im trying to return a vector2f so i can use it in this function here

for (int i = 0; i < bullet.size(); i++)
                {
                       
                        bullet[i].fire(function.checkDirection(myicetower, mymonsters)); //fire takes a vector2f
                }
 

« Last Edit: April 24, 2017, 02:16:33 am by Aerine »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10990
    • View Profile
    • development blog
    • Email
Re: How do you return a vector2f from a function.
« Reply #1 on: April 24, 2017, 02:07:03 am »
The third line misses a semicolon and what's Classname?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Aerine

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How do you return a vector2f from a function.
« Reply #2 on: April 24, 2017, 02:17:49 am »
I updated my question to be alittle more specific sorry

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10990
    • View Profile
    • development blog
    • Email
Re: How do you return a vector2f from a function.
« Reply #3 on: April 24, 2017, 02:33:43 am »
And what is function now?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Aerine

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How do you return a vector2f from a function.
« Reply #4 on: April 24, 2017, 02:51:48 am »
My function that returns a sf::vector2f is from the functions class. I simple have created a object called function to use it.

In my game class im tryiing to use this function to return a vector2f so i know where my bullet needs to go. However i get the error term does not evaluate to a function taking two arguments.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How do you return a vector2f from a function.
« Reply #5 on: April 24, 2017, 12:23:28 pm »
Is checkDirection a free function? If so, you don't need the "function." prefix.

Remember too that checkDirection needs to always return a value regardless of whether or not that if condition becomes true.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Evaghetti

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: How do you return a vector2f from a function.
« Reply #6 on: April 26, 2017, 12:43:30 am »
is checkDirection static? if so you should call it with function::checkDirection instead of function.checkDirection
(also, if function is the name of a object use the class' name instead)