Vous n'êtes pas identifié(e). Pour pouvoir écrire ou répondre à un message, vous devez vous connecter ou vous créer un compte sur JAWA.

#1 03-01-2019 10:37:48

spook1
Membre
Inscription : 12-02-2018

Modulo% and Floor functions. Are these available? ✓

I would like to create a script, to be called by an object at "get in a scene"moment.

The script will semi-randomly layout a deck of cards.

I create
- a global parameter: numPerRow
- an object, with N images, and a custom variable containing the object_number

updateobject:1:x:[100*{{_custom1_1}} % {{numPerRow}}]:0                  // calculate the column of the card
updateobject:1:y:[100*Floor[{{_custom1_1}} / {{numPerRow}}[]:0          // calculate the row of the card
updateobject:1:image:_custom_1                                                              // set the number of the image

The object is cloned N times, and then the only thing that needs to be done is, manually, adjust the custom1 parameters of the obejcts.

They will be placed in a 100x100 pixel  grid, with numPerRow cards in each row, automatically when the room loads.
When I want to finetune the lauyout, all I need to do is change the script in one place.

Hors ligne

#2 04-01-2019 08:30:44

jawa
Admin

Re : Modulo% and Floor functions. Are these available? ✓

Hello Martijn

Tou can use javascript parseInt methid and soe of the JS math library functions inside [ ] calcutulations statement to achieve that.
for instance  :
variable:position:[100*parseInt({{_custom1_1}} / {{numPerRow}})]
updateobject:1:y:{{position}}:0

modulo statement should work as any other operator.

Supported JS methods are :
parseInt
parseFloat
Math.max
Math.min
Math.abs
Math.sin
Math.cos
Math.tan


Please note that you can use other JS methods but not all of them are translated on server side (which is php coded) when the server replays the interaction effects to store game values  on the database, so the calculation result may differ or fail when you relaod your game.
I can add some if needed.
This problem won't affect standalone games whiche are only processed through the browser (JS)

Last thing, I'm not sur ypou can use [] statemends in update effect parametrs right now (so maybe you'll need to set a varaible first and use it in the updateffect parameters). If not  this is is the roadmap.


Nb : for helping positionning of movable objects on a virtual griid, it may be more easy to use the "adjustement step parameter" of movable object which will fit automactically the object on the grid at the drop.

Z

#3 08-01-2019 21:18:57

jawa
Admin

Re : Modulo% and Floor functions. Are these available? ✓

one thing a bit tricky about the modulus % sign !


you need to separate it from the number with a space otherwise it'll be interpreted as an html char code and replaced :/

{{var}}%24 will fail
{{var}} % 24 is OK

I'll try to improve that later

#4 08-01-2019 22:13:06

spook1
Membre
Inscription : 12-02-2018

Re : Modulo% and Floor functions. Are these available? ✓

hmm,

in my game #1644, script #27446, it works when I use:

variable:RUBRIC_CARD_PLACE:[{{_custom2_1}}-1]
updateobject:1:x:[{{RUBRIC_LAYOUTS$RUBRIC_CARD_PLACE$RUBRIC_DRAW}}%7*125]:1
updateobject:1:y:[125*parseInt({{RUBRIC_LAYOUTS$RUBRIC_CARD_PLACE$RUBRIC_DRAW}} / 7)+50]:0

The problem is though that the script does react to ACTION: EXAMINE an object, buit not to ACTION: GET IN a scene (see other topic in this forum)

Hors ligne

Pied de page des forums