Run script via id# or a $id string in menutype:@script?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
KutKu
Red Slime
Posts: 31
Joined: Sun Jan 01, 2017 11:17 pm

Run script via id# or a $id string in menutype:@script?

Post by KutKu »

Basically I'm trying to use string IDs (or the old school script IDs) to set a "menu item subtype (menutype:@script)" to a specific script from a selection based on an outcome.

This is a rough mock up of what I've tried so far.

Code: Select all

plotscript, menubits, begin

	(variables) (my menu, menu slot, condition)

	#stuff

# based on an outcome either A or B will be stored in string $1
	
	if (condition == 1) then(
		get script name (1, @script A)
	)
	if (condition == 2) then(
		get script name (1, @script B)
	)
	
	my menu := open menu (1)
	menu slot := add menu item (menu2)
	set menu item type (menu slot, menutype: script)

# append script outcome to the "menutype:@script"

	set menu item subtype (menu slot, @$1)
	
end
To save some time, this didn't work. However, I'm wondering if this is even possible right now? Or am I just doing this the wrong way?
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

You can't refer to a string by writing $1. You see, '$1 = "apples"' does not mean assign "apples" to $1. Instead, $...="..." is one single indivisible construct. It's very weird.

You can't lookup a script by name, but actually what you want to do is quite easy: '@scriptA' is equal to the ID number of scriptA:

Code: Select all

   set menu item type (menu slot, menutype: script) 
   if (condition == 1) then(
      set menu item subtype (menu slot, @script A)
   )
   if (condition == 2) then(
      set menu item subtype (menu slot, @script B)
   ) 
Last edited by TMC on Tue Jan 23, 2018 11:13 am, edited 3 times in total.
Post Reply