Page 76 of 400

Re: Ask a simple question, get a simple answer

Posted: Wed Jun 17, 2015 7:03 pm
by Dr.Disaster
Duncan1246 wrote:OK, and ifff(math.random()<.5,1,-1)??
iff(cond, a, b)
Returns a if cond is true, otherwise returns b.


so iff(math.random()<.5,1,-1) returns 1 for a randomly generated number below .5 and returns -1 for number equal or larger then .5

Re: Ask a simple question, get a simple answer

Posted: Wed Jun 17, 2015 7:04 pm
by Isaac
Duncan1246 wrote:So, the first line means facing is facing if facing exists, OR math.random if not. OK, and ifff(math.random()<.5,1,-1)??
Thanks for your reply!
Yes.

iff(math.random()<.5,1,-1) returns a value of 1 or -1, depending upon whether the math function returns a high or low result. The value is later given as dir to the party:turn(dir) function. It determines whether the party turns left or right.

Re: Ask a simple question, get a simple answer

Posted: Wed Jun 17, 2015 7:07 pm
by Duncan1246
Dr.Disaster wrote:
Duncan1246 wrote:OK, and ifff(math.random()<.5,1,-1)??
iff(cond, a, b)
Returns a if cond is true, otherwise returns b.
Thanks, Dr D, better to know it, it's very useful.

Re: Ask a simple question, get a simple answer

Posted: Wed Jun 17, 2015 7:21 pm
by Isaac
I've updated the earlier script.

Added the isIdle check to the turn function. Seems to work.

Funny though... I had guessed that if the party was not idle, that the turn would skip; and not happen. So I had setup a count down that could re-call the function up to 20 times before giving up... but in testing, it only ever called it once... so I removed all of it, and just left the isIdle check.
Duncan1246 wrote:it's very useful.
It's something Petri added to Grimrock's lua.

*But there is a catch to know about it; and that is that if you place functions in the results ~as in iff( true, a(), b())... both functions get called either way; not just the one indicated by the comparison.

Re: Ask a simple question, get a simple answer

Posted: Wed Jun 17, 2015 7:28 pm
by minmay
Duncan1246 wrote:
Dr.Disaster wrote:
Duncan1246 wrote:OK, and ifff(math.random()<.5,1,-1)??
iff(cond, a, b)
Returns a if cond is true, otherwise returns b.
Thanks, Dr D, better to know it, it's very useful.
Another common way to do this in Lua is

Code: Select all

cond and a or b

Re: Ask a simple question, get a simple answer

Posted: Wed Jun 17, 2015 9:07 pm
by AndakRainor
minmay wrote:Another common way to do this in Lua is

Code: Select all

cond and a or b
unless a is false !

Re: Ask a simple question, get a simple answer

Posted: Wed Jun 17, 2015 9:52 pm
by Eleven Warrior
Hi all. Thxs for the replies. Ok on most of my levels I use the code below which stops the party until I change (true) to (false)

Code: Select all

GameMode.setGameFlag("DisableMovement",true)
As soon as the code runs I need to turn the party in any of the ddirections 0,1,2,3. It should happen in I guess 0.001 seconds, that way the player does not have time to use the mouse errr 0.001 is fast yeah lol. Or ill use 0.01.

Re: Ask a simple question, get a simple answer

Posted: Wed Jun 17, 2015 10:05 pm
by Isaac
Eleven Warrior wrote:As soon as the code runs I need to turn the party in any of the ddirections 0,1,2,3.
viewtopic.php?f=22&t=7951&start=740#p96678

:spinTo(3)

Re: Ask a simple question, get a simple answer

Posted: Wed Jun 17, 2015 10:26 pm
by Duncan1246
Isaac wrote:
ifff(math.random()<.5,1,-1) returns a value of 1 or -1, depending upon whether the math function returns a high or low result. The value is later given as dir to the party:turn(dir) function. It determines whether the party turns left or right.
minmay wrote: ]Another common way to do this in Lua is

Code: Select all

cond and a or b
Thanks for these precisions.

Re: Ask a simple question, get a simple answer

Posted: Fri Jun 19, 2015 1:38 pm
by AndakRainor
Is it possible to use the dungeon editor in full-screen mode instead of windowed ? I try to set correct positions and sizes for graphics UI elements at different resolutions but the only resolution I can't test is the full screen one...