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

Re: Ask a simple question, get a simple answer

Post by Duncan1246 »

AndakRainor wrote:
Duncan1246 wrote:It's probably a silly question, but I need an answer: how can I close an image drawn with context commands? (code in my last post on this thread)
You could remove the connector, or immediately return in your drawing function when some condition is met.
I try to remove the connector with

Code: Select all

 if ( context.button("CLOSE", offset+10, (0.8 * height)+10, 90, 90) ) then
	   print("CLOSED")
	   party.party:removeConnector("onDrawGui", self.go.id, "newsheetS")
	      end
"CLOSED" is print, but image stays, and click on screen is useless. What do you means by return to the drawing function?
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 »

I mean return from the drawing function, like that:

Code: Select all

party.party:addConnector("onDrawGui", self.go.id, "newsheet")

drawFlag = true

function newsheet(self, context)
  if drawFlag then
    textlist()
    local width = context.width
    local height = context.height
    local offset = context.width * .1
    context.drawImage2("mod_assets/textures/dc_octog4_panel.tga",5,5,0,0,640, 480, width, height)
    context.drawRect(offset, (0.8 * height), 90, 30)
    context.color(0,0,0,255)
    context.drawText("CLOSE", offset+10, (0.8 * height)+20)
    if ( context.button("CLOSE", offset+10, (0.8 * height)+10, 90, 90) ) then
      print("CLOSED")
      --party.party:removeConnector("onDrawGui", self.go.id, "newsheet")
      drawFlag = false
    end
    context.font("large")
    context.drawParagraph(bufferpage, offset, context.height*.1, width*.8)
  end
end
Re-Edit: oops! I did not see that you used self.go.id in your removeConnector. This can not work, as in this function, self is the party component. You should use instead:

Code: Select all

party.party:removeConnector("onDrawGui", "myScript", "newsheet")
where "myScript" is the ID of your script entity with the newsheet function.
Last edited by AndakRainor on Sun Nov 20, 2016 2:23 am, 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 »

AndakRainor wrote:I mean return from the drawing function, like that:

Code: Select all

party.party:addConnector("onDrawGui", self.go.id, "newsheet")

drawFlag = true

function newsheet(self, context)
  if drawFlag then
    textlist()
    local width = context.width
    local height = context.height
    local offset = context.width * .1
    context.drawImage2("mod_assets/textures/dc_octog4_panel.tga",5,5,0,0,640, 480, width, height)
    context.drawRect(offset, (0.8 * height), 90, 30)
    context.color(0,0,0,255)
    context.drawText("CLOSE", offset+10, (0.8 * height)+20)
    if ( context.button("CLOSE", offset+10, (0.8 * height)+10, 90, 90) ) then
      print("CLOSED")
      --party.party:removeConnector("onDrawGui", self.go.id, "newsheet")
      drawFlag = false
    end
    context.font("large")
    context.drawParagraph(bufferpage, offset, context.height*.1, width*.8)
  end
end
Edit: if the image stays after you removed the connector, it means you added the connector twice or more, and so removing it one time was not enough.
The hook is read only once, but the flag solution works as intended, thanks a lot!
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 »

See my previous edit, I made several mistakes in my first answer, I should sleep more xD

If you want to use this function one time only, you should use the remove connector method. If you will use it several times, the flag solution can be more convenient, just switch it when you need it.
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 »

AndakRainor wrote:See my previous edit, I made several mistakes in my first answer, I should sleep more xD

If you want to use this function one time only, you should use the remove connector method. If you will use it several times, the flag solution can be more convenient, just switch it when you need it.
Here it's 1h33 am, thanks to you I can now have some rest, I wish the same to you. :D
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

minmay wrote:Epic items are counted when the dungeon begins to get the maximum number. If this count is incorrect because you want to spawn an additional epic item, you can just use GameMode.setMaxStatistic() to fix it.
thanks all, for your answer!
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

I have searched some informations in the scripting reference about

Code: Select all

GameMode.setMaxStatistic()
but I did not found anything. Someone can help please? what argument should be used for counting the epic items?
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

GameMode.setMaxStatistic(stat,max)
Let's say you want to increase the maximum number of epic items by one. Then you'd call:

Code: Select all

GameMode.setMaxStatistic("epic_items_found",GameMode.getMaxStatistic("epic_items_found")+1)
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
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:GameMode.setMaxStatistic(stat,max)
Let's say you want to increase the maximum number of epic items by one. Then you'd call:

Code: Select all

GameMode.setMaxStatistic("epic_items_found",GameMode.getMaxStatistic("epic_items_found")+1)
Thank you. 8-)

Where does it say "epic_items_found" is a statistic?
(Is there a published list of all the LoG2 statistics?)
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

polymorphs
potions_mixed
spells_cast
power_attacks
unarmed_attacks
firearm_attacks
missile_attacks
throw_attacks
melee_attacks
ladders_climbed
pit_falls
tiles_dived
tiles_moved
gold_keys_used
levels_visited
fish_caught
skulls_found
treasures_found
essences_found
power_gems_found
epic_items_found
items_found
monsters_killed
secrets_found
play_time
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.
Post Reply