This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-03-21 20:43:10

PullJosh
Scratcher
Registered: 2011-08-01
Posts: 500+

Some serious scripting help needed

I was trying to make a project that lets you create variables, get the values of the variables, and change the values of variables... All in one script! The script I have is pretty long so go get some hot chocolate and prepare yourself. Before we start, I would like to tell you what should happen. If you type a variable that has been made, it will say what its value is. If you type something random, it will make a variable and ask you to set it. If you type a variable name with a _ before it, it will let you change the value of that variable. If you type a non-existing variable with a _ before it, it will give you an error message. OK. Here we go...

when gf clicked
forever
ask [] and wait
set [answer variable v] to (answer)
if <not <(letter (1) of (answer variable)) = [_] >>
if <not <[variables v] contains (answer)>>
add (answer) to [variables v]
ask [What should it be set to?] and wait
add (answer) to [values v]
else
set [test v] to (1)
if <not < (item (test) of [variables v]) = (answer)>>
repeat until <(item (test) of [variables v]) = (answer)
change [test v] by (1)
end
end
say (item (test) of [values v]) for (2) secs
end
else
delete [all v] of [answer_list v]
set [test v] to (1)
repeat (length of (answer variable))
add (letter (test) of (answer variable)) to [answer_list v]
change [test v] by (1)
set [answer variable v] to ()
repeat (length of [answer_list v]
set [answer variable v] to (join (answer variable)(item (test) of [answer_list v]))
change [test v] by (1)
end
if <[variables v] contains (answer variable v)>
set [test v] to [1]
repeat until <(item (test) of [variables v]) = (answer variable)>
change [test v] by (1)
end
ask [What would you like the variable to be set to?] and wait
replace item (test) of [values v] with (answer)
else
say [That variable does not exist. Try making it.] for (2) secs
end
end
It's not working so, um... could you help?  tongue

Last edited by PullJosh (2012-03-21 20:45:05)


http://www.blocks.scratchr.org/API.php?action=text&amp;string=I'm_on_vacation!&amp;xpos=155&amp;ypos=90&amp;font_size=30&amp;bgimage=http://imageshack.us/a/img339/7215/sspeechsigapiforwords.png

Offline

 

#2 2012-03-21 21:31:42

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Some serious scripting help needed

I really couldn't understand how you were trying to change the value of a variable, try this:

set [i] to (1)
set [name] to []
repeat ((length of (answer variable)) -(1))
change [i] by (1)
set [name] to (join (name) (letter (i) of (answer variable)))
end
if<[variables v] contains (name)>
ask [replace with what?] and wait
set [i] to (0)
repeat (length of [variables v])
if<(item (i) of [variables v]) = (name)>
replace item (i) of [values v] with (answer)
stop script     // or let it run to completion if you want to keep it in one loop.
end
end
else
error
end


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2012-03-22 15:58:57

PullJosh
Scratcher
Registered: 2011-08-01
Posts: 500+

Re: Some serious scripting help needed

MoreGamesNow wrote:

I really couldn't understand how you were trying to change the value of a variable, try this:

set [i] to (1)
set [name] to []
repeat ((length of (answer variable)) -(1))
change [i] by (1)
set [name] to (join (name) (letter (i) of (answer variable)))
end
if<[variables v] contains (name)>
ask [replace with what?] and wait
set [i] to (0)
repeat (length of [variables v])
if<(item (i) of [variables v]) = (name)>
replace item (i) of [values v] with (answer)
stop script     // or let it run to completion if you want to keep it in one loop.
end
end
else
error
end

What part do I need to replace it with?


http://www.blocks.scratchr.org/API.php?action=text&amp;string=I'm_on_vacation!&amp;xpos=155&amp;ypos=90&amp;font_size=30&amp;bgimage=http://imageshack.us/a/img339/7215/sspeechsigapiforwords.png

Offline

 

#4 2012-03-22 16:28:15

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Some serious scripting help needed

The final "else" part (setting a variable)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2012-03-22 16:47:50

PullJosh
Scratcher
Registered: 2011-08-01
Posts: 500+

Re: Some serious scripting help needed

MoreGamesNow wrote:

The final "else" part (setting a variable)

My scripting works. The problem is that you have to type what you want to have happen multiple times before it will do something.


http://www.blocks.scratchr.org/API.php?action=text&amp;string=I'm_on_vacation!&amp;xpos=155&amp;ypos=90&amp;font_size=30&amp;bgimage=http://imageshack.us/a/img339/7215/sspeechsigapiforwords.png

Offline

 

#6 2012-03-22 17:07:38

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Some serious scripting help needed

Ah, I understand now.  Unfortunately, in isolation, a script with the same input should result in the same output, so I'm not sure how typing the exact same thing twice would result in different outcomes.  Are there any other scripts?


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#7 2012-03-22 17:42:11

PullJosh
Scratcher
Registered: 2011-08-01
Posts: 500+

Re: Some serious scripting help needed

MoreGamesNow wrote:

Ah, I understand now.  Unfortunately, in isolation, a script with the same input should result in the same output, so I'm not sure how typing the exact same thing twice would result in different outcomes.  Are there any other scripts?

Nope. I'll post it online you can download it for a bit more... well... a bit better result.


http://www.blocks.scratchr.org/API.php?action=text&amp;string=I'm_on_vacation!&amp;xpos=155&amp;ypos=90&amp;font_size=30&amp;bgimage=http://imageshack.us/a/img339/7215/sspeechsigapiforwords.png

Offline

 

#8 2012-03-22 17:44:46

PullJosh
Scratcher
Registered: 2011-08-01
Posts: 500+

Re: Some serious scripting help needed

Okay. I got it. Here it is!


http://www.blocks.scratchr.org/API.php?action=text&amp;string=I'm_on_vacation!&amp;xpos=155&amp;ypos=90&amp;font_size=30&amp;bgimage=http://imageshack.us/a/img339/7215/sspeechsigapiforwords.png

Offline

 

#9 2012-03-22 18:01:02

prototype47
Scratcher
Registered: 2010-02-25
Posts: 98

Re: Some serious scripting help needed

Actually quite similar to my Scratch Epic Database project I've been working on.  Except mine has something more like 2000 blocks of code lol.  This should work alright, however I would have to download it and study the scripting a little more, which I will hopefully do later today.

Last edited by prototype47 (2012-03-22 18:02:00)


SED is temporarily abandoned while I move onto new areas, such as AI with pathfinding, individual reactions, and group communication.  More complex projects are also brewing.
http://dl.dropbox.com/u/41930734/newsig.png

Offline

 

#10 2012-03-22 18:56:55

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Some serious scripting help needed

Here you go.  smile

Last edited by MoreGamesNow (2012-03-22 18:57:04)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#11 2012-03-24 10:22:52

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Some serious scripting help needed

Closed by request of the topic owner.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer