how to find entity (entities) on map [Solved]

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
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: how to find entity (entities) on map

Post by Jouki »

SnowyOwl47 wrote:Hmm @Jouki Delete the spaces around the i ok
still doesnt work :(
JohnWordsworth wrote:When building an entity name from variables and then retrieving that entity, you will want to do some string concatenation and use the "findEntity" function. The following first defines a flexible function that can turn on a whole bunch of lights that all start with the same ID in the editor and then defines a specific "utility function" that you can call from a pressure plate that turns on all lights in your dungeon that have the name "top_floor_lights_i" (where i starts at 1 and goes up to the last light it finds using this pattern).

Code: Select all

-- A generic function that will turn on the light and particle component 
-- for all entities in the dungeon that have the id "prefix_i" where
-- "prefix" is the parameter given to this method and "i" counts up from 1.

function turnOnLights(prefix) 
  local i = 1;
  local entity = findEntity(prefix .. "_" .. i);

  while entity ~= nil do
    if entity.light ~= nil then
	  entity.light:enable();
    end

    if entity.particle ~= nil then
      entity.particle:enable();
    end

    i = i + 1;
    entity = findEntity(prefix .. "_" .. i);
  end
end

-- 
-- This function is one you can hook into a pressure plate and it will 
-- turn on all lights in your dungeon with the name "top_floor_lights_i"
-- ie. top_floor_lights_1, top_floor_lights_2, ...

function turnOnTopFloorLights()
	turnOnLights("top_floor_lights");
end
Hope this helps!
holy... ok, it's working :) I should go through this code and learn as much as I can from that.
Btw. is there (I'm almost sure it is) something like 'sleep(2000)' (ms) I can handle cool effect "a slowly starting all-light effect" I mean turning them on one by one or any other way.

There's a view how it looks :P
Image
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: how to find entity (entities) on map

Post by JohnWordsworth »

I'm gonna hold off answering that for a short while... While I know that you could put a solution together using timers, I'm sure I read somewhere from Petri that there is a function you can use to just exactly this sort of thing (put a 2 second pause into a script). I'll try to find it, but I can't remember if it was a blog post or forum post or whether he posted a code example or just text! Lol
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: how to find entity (entities) on map

Post by NutJob »

I thought .gif stopped existing a decade ago. ~laughs~

Glad you got it working.
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: how to find entity (entities) on map

Post by Jouki »

JohnWordsworth wrote:I'm gonna hold off answering that for a short while... While I know that you could put a solution together using timers, I'm sure I read somewhere from Petri that there is a function you can use to just exactly this sort of thing (put a 2 second pause into a script). I'll try to find it, but I can't remember if it was a blog post or forum post or whether he posted a code example or just text! Lol
that's ok, I forgot about timers. I can do that with timer and counter(s)
NutJob wrote:I thought .gif stopped existing a decade ago. ~laughs~

Glad you got it working.
iI just dont want to put any video from the map on youtube right now :P
Post Reply