Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,641
Reaction score
1,474
First Language
French
Primarily Uses
RMMV
hi am trying make a easy way to auto increase a variable .


in this example, so 


when i showPicture , the var PID and defxy[1] need to increase after show.
Is work good for ++, but not the +=


function ActionKey(WhatToDo) {
var PID = 83; // default PID for actionkey huds
var defxy = [1200,500]; // default x y pos for actionkey
var PH = 125; // picture fixed heigth from Action-Key.png
if (WhatToDo==='show') {
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1]+=PH, 100, 100, 255, 0);
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1]+=PH, 100, 100, 255, 0);
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1]+=PH, 100, 100, 255, 0);
}
}






The way clearer.
Why does this return me 5, 6 and not 5, 5  ?


var A = 5;
var B = 5;
console.log((A++)+ ' ' + (B+=1)); // return 5 6




That fµ©£ me, all the easy way, with which I would like make my code.
Is there a way? or is a buggy javascript ?
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,693
Reaction score
3,031
First Language
Tagalog
Primarily Uses
RMVXA
The way clearer.
Why does this return me 5, 6 and not 5, 5  ?



var A = 5;
var B = 5;
console
.log((A++)+ ' ' + (B+=1)); // return 5 6



It returns 5,6 instead of 5,5 because += sets it to 6 before the return call..


++ adds but returns the original value


+= adds and returns the new value


if showing it similar to a code makes more sense

Code:
// var ++ works like this

var A = 5
var A_original = A
A = A + 1
return A_original

// var += value works like this

var A = 5
A = A + value
return A
 
Last edited by a moderator:

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,641
Reaction score
1,474
First Language
French
Primarily Uses
RMMV
exist somes ways to syntaxe ++ returns the original value , but with a variable ?


example:

Code:
A = 5;
B = 5;

Console.log( (A++B) ); // example return 5
Console.log( (A++B) ); // example return 10
Console.log( (A) ); // example return 15
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,693
Reaction score
3,031
First Language
Tagalog
Primarily Uses
RMVXA
IDK if that's possible, but why not just make it such that your variables are


var PH = 125;
var defxy = [1200,500-PH];



so that your first defxy[1] += line will return 500 which is the first value that you want to use
 
Last edited by a moderator:

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,641
Reaction score
1,474
First Language
French
Primarily Uses
RMMV
@Engr. Adiktuzmiko


The complete code is a little more laborious.
I had purified it for my question.


But thank you, I think that answers my question.
we cannot
I will do as I usually do.


EDIT: HAHA ok '  why not just make it such that your variables '


ok is true, Thank you I was tired
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,693
Reaction score
3,031
First Language
Tagalog
Primarily Uses
RMVXA
I'm not sure if you really cant, and I can't test so I just gave the most plausible answer that I can think of.


You can still test A++B in case it might actually be doable


now if you can't do my suggestion of still using += with your original variable reduced by the first increment (but IDK of a situation where that cannot be done so far), then you could just do


if (WhatToDo==='show') {
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1], 100, 100, 255, 0);
defxy[1]+=PH;
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1], 100, 100, 255, 0);
defxy[1]+=PH;
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1], 100, 100, 255, 0);
defxy[1]+=PH;
}




EDIT : so you can do the 500-PH edit?
 
Last edited by a moderator:

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,641
Reaction score
1,474
First Language
French
Primarily Uses
RMMV
I


EDIT : so you can do the 500-PH edit?



Yes i test and it worked impeccably it was the way I wanted to build my code.
It suffisait d'y thought, I don't regret my question you helped.
Thank you.


Example: for auto incrementation


function ActionKey(WhatToDo) {
var PID = 83; // default PID for actionkey huds
var PH = 125; // picture fixed heigth from Action-Key.png
var defxy = [1200,500-PH]; // default x y pos for actionkey

if (WhatToDo==='show') {
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1]+=PH, 100, 100, 255, 0);
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1]+=PH, 100, 100, 255, 0);
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1]+=PH, 100, 100, 255, 0);
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1]+=PH, 100, 100, 255, 0);
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1]+=PH, 100, 100, 255, 0);
$gameScreen.showPicture(PID++, 'Action-Key', 0, defxy[0], defxy[1]+=PH, 100, 100, 255, 0);
}
}


@  
 
Last edited by a moderator:

Latest Threads

Latest Posts

Latest Profile Posts

I've got good news and bad news. The good news is, there aren't any bad news to report. The bad news is, there aren't any good news to report.

Or as others say, yesterday was uneventful.


I am curious that can you "understand/get the point" about what does this place do generally?
(ARPG game)
If anyone knows any C# programmers, please send them my way.
Chilling at night in a tavern.
ChillingAtTavern.png

After 'multiple breakdowns', it's finally over. 10/10 will do this again.
Ever notice that villains can reform and become better people, but heroes can only ever die... or live long enough to see themselves become villains?

Isn't that interesting?

Forum statistics

Threads
129,845
Messages
1,205,674
Members
171,007
Latest member
JamesAnent
Top