Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: Ask a simple question, get a simple answer

Post 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
Last edited by Dr.Disaster on Wed Jun 17, 2015 7:05 pm, edited 1 time in total.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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.
Last edited by Isaac on Wed Jun 17, 2015 11:02 pm, edited 1 time in total.
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Ask a simple question, get a simple answer

Post 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.
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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.
Last edited by Isaac on Wed Jun 17, 2015 7:29 pm, edited 1 time in total.
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post 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
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post 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 !
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Ask a simple question, get a simple answer

Post 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.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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)
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Ask a simple question, get a simple answer

Post 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.
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post 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...
Post Reply