Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,635
Reaction score
1,458
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,023
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,635
Reaction score
1,458
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,023
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,635
Reaction score
1,458
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,023
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,635
Reaction score
1,458
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

SF_Vehicle2 and SF_People2_8 added!
index.php

If I made an 8-bit-esque, dark fantasy tileset/graphics pack, would y'all be into that? Like, for Dark Souls demakes, Nintendo vampire wannabes, Castlevania ripoffs and such?

Working title: Alice's 8-bit Gothic. Do or not do? (Like do y'all even use 8-bit style graphics?)
I love editing things .
16b6a8abb5d27bf617d9b802cd5b868a.jpg

* Wall frames made with pencil photo and program photos, * Leaf and Pot, with cliché ideas of flowers
*bear on top of the closet belonging to the art of whtdragon lol.
No better feeling than part of a project just clicking into place without a single issue.

Forum statistics

Threads
118,441
Messages
1,115,999
Members
155,402
Latest member
Bansher
Top