Writing the result of a function on a scroll ?

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
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Writing the result of a function on a scroll ?

Post by cromcrom »

I all, I would like to have the list of my custom skills, and their values, appear on a scroll (from a function that would return this, to make things easier). However, ScrollText doesn"t seem to allow this. I also tried to make the scroll usable, but it disappears when used. Any idea please ?
A trip of a thousand leagues starts with a step.
User avatar
QuintinStone
Posts: 72
Joined: Sat Nov 01, 2014 9:58 pm

Re: Writing the result of a function on a scroll ?

Post by QuintinStone »

You would do it like this:

scroll_1.scrollitem:setScrollText(myscript.getSkillInfo())
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Writing the result of a function on a scroll ?

Post by cromcrom »

Thanks. But so, I cannot create an object like that,

Code: Select all

 defineObject{ name = "skills_scroll_crom",
   baseObject = "scroll",
   components = { 
    { 
      class="ScrollItem",
	  ScrollText = (cromlibrary.scrolltextfunc()),
  },  
   }
   }
I would have to spawn it first, i guess.
A trip of a thousand leagues starts with a step.
User avatar
QuintinStone
Posts: 72
Joined: Sat Nov 01, 2014 9:58 pm

Re: Writing the result of a function on a scroll ?

Post by QuintinStone »

Okay, if your code doesn't work as is, maybe you could set the text in the component's onInit()?

I'm new to Grimrock modding and lua, but...

Code: Select all

defineObject
{
  name = "skills_scroll_crom",
  baseObject = "scroll",
  components = {
    {
      class="ScrollItem",
      onInit = function (self)
        self.scrollItem:setScrollText(cromlibrary.scrolltextfunc())
      end
    }, 
  }
}
Then you'd just need to spawn one. Assuming onInit works like I think it does (I have not done any testing with it yet).
Crypt of Zulfar
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Writing the result of a function on a scroll ?

Post by cromcrom »

Thanks for trying. The onInit hook is not a scrollItem class hook. I will give it a try with on equip.
A trip of a thousand leagues starts with a step.
User avatar
QuintinStone
Posts: 72
Joined: Sat Nov 01, 2014 9:58 pm

Re: Writing the result of a function on a scroll ?

Post by QuintinStone »

cromcrom wrote:Thanks for trying. The onInit hook is not a scrollItem class hook. I will give it a try with on equip.
Doh, sorry, the scripting reference says it's part of the Component base class.
Crypt of Zulfar
User avatar
Jgwman
Posts: 144
Joined: Thu Jun 28, 2012 10:14 pm

Re: Writing the result of a function on a scroll ?

Post by Jgwman »

What do you mean by "scrollText doesn't seem to allow this"? It doesn't seem very difficult, just set the text on the scroll to the function return value. Shouldn't need a custom asset. If it involves numbers pass the return to tostring() first. What am I missing here?
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Writing the result of a function on a scroll ?

Post by cromcrom »

No its me, I am not good at all this. Nothing worked. The closest I came was calling the function with scrollItem = (funct()), but I have to press F5 for the text to appear.

so if i put this function on top of the object.lua

Code: Select all

function scrolltextfunc()
return "blah blah blah"
end
and then create a skill scroll like that:

Code: Select all

 defineObject{ name = "skills_scroll_crom",
   baseObject = "scroll",
   components = { 

    { 
      class="ScrollItem",
ScrollText = (scrolltextfunc())
  },  
   }
   }
and I add the scroll to the dungeon in the editor, "blah blah blah" will appear on the scroll, but only once I reload the dungeon by pressing F5. I would like it to appear right from the start, just like in good ol' LoG1 ^^
A trip of a thousand leagues starts with a step.
User avatar
QuintinStone
Posts: 72
Joined: Sat Nov 01, 2014 9:58 pm

Re: Writing the result of a function on a scroll ?

Post by QuintinStone »

cromcrom wrote:No its me, I am not good at all this. Nothing worked. The closest I came was calling the function with scrollItem = (funct()), but I have to press F5 for the text to appear.

...

and I add the scroll to the dungeon in the editor, "blah blah blah" will appear on the scroll, but only once I reload the dungeon by pressing F5. I would like it to appear right from the start, just like in good ol' LoG1 ^^
Well you have to hit F5 to reload the changes into the preview window.
Crypt of Zulfar
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Writing the result of a function on a scroll ?

Post by cromcrom »

Sure, but this doesn't work ingame. I am pretty pissed at these cumbersome gui contexts...
+ impossible to call functions from onuse, that makes items dissappeared, while it was so "easy" in log 1. it feels like a step backwards :-(
A trip of a thousand leagues starts with a step.
Post Reply