Is there a way to reference a select range of numbers?

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

Moderators: marionline, SDHawk

Post Reply
User avatar
Gigglyardo
Slime
Posts: 9
Joined: Sun Aug 16, 2015 1:20 am

Is there a way to reference a select range of numbers?

Post by Gigglyardo »

Let's say I wanna write a script that refers to a range of npc id's from 6 to 9, but not 0 to 5 or 10 to 999.
so like

if (npc at spot(1,1) == 6 to 9) then (show text box (1))

can it be done?
ArtimusBena
Slime Knight
Posts: 251
Joined: Thu Nov 16, 2017 5:22 am

Re: Is there a way to reference a select range of numbers?

Post by ArtimusBena »

I will share one of my little custom commands. In that example (untested):

Code: Select all

script, var in range, var, min, max, begin
if (var >= min && var <= max) then (return (1))
end

script, yourscript, begin
variable (id)
id := (get npc id (npc at spot(1, 1)))
if (var in range (id, 6, 9)) then (show textbox(1))
end
Do you make love with the same urgency you make games?
ArtimusBena
Slime Knight
Posts: 251
Joined: Thu Nov 16, 2017 5:22 am

Re: Is there a way to reference a select range of numbers?

Post by ArtimusBena »

There's other ways to do it of course.

One way is a switch.

Code: Select all

script, yourscript, begin
variable (id)
id := (get npc id (npc at spot(1, 1)))

switch (id) do (
case (26, 47, 28, 19) show textbox (1)
)
end
This would also let you choose IDs that aren't all neatly in a range.
Do you make love with the same urgency you make games?
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6461
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Re: Is there a way to reference a select range of numbers?

Post by Spoonweaver »

Gigglyardo wrote: Mon Feb 14, 2022 6:08 pm Let's say I wanna write a script that refers to a range of npc id's from 6 to 9, but not 0 to 5 or 10 to 999.
so like

if (npc at spot(1,1) == 6 to 9) then (show text box (1))

can it be done?

Code: Select all

if (npc at spot(1,1)>=6,and,npc at spot(1,1)<=9) then (show text box (1))
ArtimusBena
Slime Knight
Posts: 251
Joined: Thu Nov 16, 2017 5:22 am

Re: Is there a way to reference a select range of numbers?

Post by ArtimusBena »

Spoon's response is unfortunately invalid. The "npc at spot" command returns an npc reference. Not an ID.

All references are negative numbers and refer to individual instances of npcs on the map. -300 to -1. Therefore, his above code above will always be false.
Do you make love with the same urgency you make games?
User avatar
Gigglyardo
Slime
Posts: 9
Joined: Sun Aug 16, 2015 1:20 am

Re: Is there a way to reference a select range of numbers?

Post by Gigglyardo »

this has been quite helpful and informative 👍
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6461
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Re: Is there a way to reference a select range of numbers?

Post by Spoonweaver »

ArtimusBena wrote: Mon Feb 14, 2022 11:54 pm Spoon's response is unfortunately invalid. The "npc at spot" command returns an npc reference. Not an ID.

All references are negative numbers and refer to individual instances of npcs on the map. -300 to -1. Therefore, his above code above will always be false.
This is true if not missing the point.
I assumed your example, Gigglyardo, was a for instance example. (as it clearly was)
and the answer was provided in that context to best illustrate the simplest solution to the problem you proposed.
I would assume that if you want to refer to npc's you'd notate them correctly and if you want to refer to npc id's you'd notate that.
You sort of did both and neither in your example, but that's fine as long as you understand that point.

As Artimus has shown though, there is a lot more to the question you asked and indeed a lot more to plotscripting.
Your question honestly begs several other questions in order to really reply in the most helpful way, though we tried not to answer questions with questions. The truth is though, the easiest answer to the question is a simple, Yes.
We generally answer questions on the discord https://discord.gg/gjdhRGkr
I invite you to join with any other questions you may have.
Post Reply