C++ Set value from current variable

Hi i was trying to make game engine I want change position of variable with player coordinates normally i do with this:
foobar = foobar2;

but i needed do something like
drawBox(= tra_x,=tra_y,=tra_z

but i don't want always updated data.

like if player on 15 0 3

variable needed stay at 15 0 3
not 16 0 4.

it's updates when i use foo = tra_x;
like

I want just stop update of variable.

It's needed to be not changed always same number until user does same thing again.

user goes eg: 17 1 6

and does same code here.

it needed be 17 1 6 not 15 0 3.



my plan was that how i can do this.

sorry for bad english.
Last edited on
I didn't understand any of that.
Furthermore, the problem isn't the bad English in itself; the problem is you're not clearly explaining what the problem is. The only parts that that look even close to code are drawBox(= tra_x,=tra_y,=tra_z and foo = tra_x;, the first of which isn't even C++.

Your game should have some sort of event loop or message callback that receives input, e.g. if you press down a key, this triggers an event. Perhaps during this event, you simply set a bool down = true. Then, in the main logic for that frame, if down is currently true, move the player down
e.g.
1
2
3
4
if (down)
{
    player.y -= some_delta_amount; // depending on coordinate system, this might be +=
}


During a "key released" event, you would then set down = false, and the player will no longer move.

Last edited on
you could do this. I don't know if it is appropriate to your question.

void foo ( vector xyz, bool update = false)
{
if(update)
something = xyz; //whatever update statement(s) could be complicated etc.
//this could also be return; statement to do nothing at all if there is nothing to do.
//that seems kinda lame, better to not call the function if it won't do anything, if possible.

other_code();
}

if you call it with
foo(abc); // will not update
foo(abc, false); //will not update
foo(abc, true); //WILL UPDATE
and you can get snarky..
foo(abc, oldabc!=abc); //will update if oldabc != abc, that is, the expression is true.

Last edited on
i need say this.
I want build a box with drawBox(x,y,z)
and i want be x y z same as my player position.
But when player moves the box follows me i don't want that.
I don't want box follow me.
Last edited on
So... you want x, y, z to be the initial player position, but when the player moves, you don't want x, y, z to be updated to reflect the new player position?
then the 2 things need distinct coordinates, and they are initialized to the same value, and tracked distinctly. There may be oddball things you could do in weird circumstances, eg if the box is fixed and the player moves, you can define the box at a local 0,0,0 coordinate and the player as offsets to that (giving you the distance the player is from the box easily, or whether he is inside the box easily, and so on, if that is the goal ... with one size zeros you can do less math to get some answers). But its really just as easy to stay in the global coordinate system unless you see a meaningful reason to do otherwise.
how i can do that
i was now trying from read file
needed code of that

i was generating a new cube but now when user inputs newcube then next lines would be coordinates of cube
Topic archived. No new replies allowed.