Forum

> > Stranded II > Scripts > I messed up another script.
Forums overviewStranded II overview Scripts overviewLog in to reply

English I messed up another script.

9 replies
To the start Previous 1 Next To the start

old I messed up another script.

aimeewilbury
User Off Offline

Quote
I created a "foal," a smaller version of a horse that would become an adult horse when you tamed it. However somehow I managed to mess up the script. It eats the apple and becomes tame but is still a foal.

The ID of the foal is 96 and the "tame horse" (which doesn't dump you) is 86:
1
2
3
4
5
6
7
8
9
10
11
//Make adult
	if (gotstate("self","tame")) {
		play "build_finish.wav"
		local $x,$z;
		$x=getx("self");
		$z=getz("self");
		create "unit",86,$x,$z;
		freevar $tmp,$x,$z;
		free "self";
	}
script=end

Any suggestions? It's probably something very simple

EDIT: Works if you put it under on:use, but it'd be nice for it to happen automatically.

old Re: I messed up another script.

Hurri04
Super User Off Offline

Quote
you forgot the brackets since s2 cmd create is a command which returns a value (which you normally want to save into a variable in case you need it for any further commands in the script):

× create "unit",86,$x,$z;               (WRONG)

> create("unit",86,$x,$z);                    (BETTER)

√ $id=create("unit",86,$x,$z);               (RIGHT)

also it seems that leaving the variable away in some cases also causes problems with the scripting syntax. I'm not sure whether this caused your problem but I e.g. had problems with s2 cmd setlocal and s2 cmd getlocal when doing so...



further it seems that there's a semicolon missing again:
1
play "build_finish.wav"
1
play "build_finish.wav";


little tip:
do not use the same name for a variable in various scripts, like $x, $y, $z and so on, this might also cause interferences.
better use names which are more unique, e.g. $pony_x etc.

another tip:
usually you dont need to use the s2 cmd freevar command so often, since it's of no real use in such small scripts.
Stranded 2 can handle up to a few 1000 variables without using significantly more memory.

old Re: I messed up another script.

aimeewilbury
User Off Offline

Quote
Yeah I noticed the missing semicolon (it broke the script) but I had to leave so I didn't have time to fix it in the post.

So I fixed the code and here it is (I had the wrong unit, it was #86 for the Wild Horse and #92 for the Tame Horse:

1
2
3
4
5
6
7
8
if (gotstate("self","tame")) {
			play "build_finish.wav";
			local $x,$z;
			$x=getx("self");
			$z=getz("self");
			$id=create("unit",92,$x,$z);
			free "self";
		}

It still remains a foal and when I try to "use" it (I removed the on:use thing) it says something about Unit 100 which doesn't exist.

old Re: I messed up another script.

Hurri04
Super User Off Offline

Quote
uh, found the problem. must be blind or something...

when using the s2 cmd if command you have to compare something:
1
if (gotstate("self","tame")) {

since you want the wild horse to be tamed, I guess it has to llok like this:
1
if (gotstate("self","tame")==0) {
so when the wild horse does not have the tame state, it will become a tamed horse.

I'm not sure whether this is what you want, because you could actually remove the if-part then since a wild horse cannot have the tamed state because otherwise it would be a tamed horse...

old Re: I messed up another script.

Apache uwu
User Off Offline

Quote
No I don't think that's the problem.

Is gotstate("self","tame") a Boolean or with 1s and 0s?

Yeah you need to compare with an actually number.

1
if (gotstate("self","tame")) {

is exact to

1
if (gotstate("self","tame")==true) {

old Re: I messed up another script.

Hurri04
Super User Off Offline

Quote
user Apache uwu has written
No I don't think that's the problem.

Is gotstate("self","tame") a Boolean or with 1s and 0s?

Yeah you need to compare with an actually number.

1
if (gotstate("self","tame")) {

is exact to

1
if (gotstate("self","tame")==true) {

this wont work since commands which return a value always retum numbers, in this case 1 or 0, where 0 means false and 1 means true.

try it the ways I showed you before or with a 1 instead of the 0, I'm not really sure what you want to happen so I cant tell which one is the right solution (and there is still the 3rd solution of leaving the if line away).

old Re: I messed up another script.

aimeewilbury
User Off Offline

Quote
I changed the trigger to on:changeday which is logical as foals don't become horses instantly :). I also fixed the boolean thing so heres the current looking code:

1
2
3
4
5
6
7
8
9
10
//Make adult
	on:changeday {
		if (gotstate("self","tame")==1){
			local $x,$z;
			$x=getx("self");
			$z=getz("self");
			$id=create("unit",92,$x,$z);
			free "self";
		}
	}
To the start Previous 1 Next To the start
Log in to reply Scripts overviewStranded II overviewForums overview