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

#1 2012-07-16 14:28:37

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

help with scripts

im making a game where at the start theres a cpu button and a 2 player button. so far the cpu button works, how do i make the sprite that currently chases another sprite switch to player controls if a button is pressed when the game is started?

Offline

 

#2 2012-07-16 14:31:46

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

Re: help with scripts

bump

Offline

 

#3 2012-07-16 14:37:51

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

Re: help with scripts

ok nvm but how do i only enable moving with arrow keys when i receive a certain broadcast??

Offline

 

#4 2012-07-16 14:38:19

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

Re: help with scripts

Um...it is only been 5 minutes.  Anyway, you have to use if blocks.


http://i47.tinypic.com/2iaa73k.png

Offline

 

#5 2012-07-16 14:42:58

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

Re: help with scripts

something a bit more specific plz

Offline

 

#6 2012-07-16 15:05:05

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: help with scripts

Give the sprite a binary or boolean variable. Binary will be 0 or 1, boolean True or False. I'll use a boolean for this example. Make a variable called CPU on the sprite. Then, if the player selects to control the sprite, set the CPU variable to False. If the player doesn't select it and the game will control the sprite, set this variable to True.

In game, use this to assign control to the player or CPU, for example if the sprite has the CPU variable as True, then don't let the player control it. An easy way to do this is by using the 'If else" control block. If CPU = True, execute the game controls; Else allow the player to control it.

Hope you can follow this  smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#7 2012-07-16 15:49:46

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

Re: help with scripts

possibly following it, not sure if i am

Offline

 

#8 2012-07-16 15:52:57

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

Re: help with scripts

ok, i have   

when i receive 1 player
set CPU to True

Offline

 

#9 2012-07-16 15:52:59

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: help with scripts

What are you not following?  smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#10 2012-07-16 16:01:21

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

Re: help with scripts

ok that didnt work

on the chasing sprite i have when i recieve a certain broadcast from the cpu button to set the variable CPU to True
and when i recieve a broadcast from the 2 player button to set it to False
when gf clicked hide variable CPU
                         
                       
when gf clicked if CPU = True
                       blank

Offline

 

#11 2012-07-16 16:03:54

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: help with scripts

Make the player only able to control it if CPU = False, eg:

Forever
If CPU = False
     player controls, eg if right arrow clicked etc
ELSE
     CPU controls

smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#12 2012-07-16 16:12:44

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

Re: help with scripts

ok now how do i put player controls inside an if/else?

Offline

 

#13 2012-07-16 16:23:37

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

Re: help with scripts

if-else didnt work so i used a forever with double ifs

btw thx for all ur help prestige

Offline

 

#14 2012-07-16 16:28:23

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

Re: help with scripts

so i need to know how to put key controls inside an if

Offline

 

#15 2012-07-16 17:17:12

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: help with scripts

FOREVER
  IF CPU = False

        if right key pressed
              change x by 1
        if left key pressed
              change x by -1
   ELSE
       CPU controls

Last edited by Prestige (2012-07-16 17:17:24)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#16 2012-07-16 17:38:39

XXtitaniumfangXX
New Scratcher
Registered: 2012-07-12
Posts: 57

Re: help with scripts

thx a lot prestige, my game works  big_smile

Offline

 

#17 2012-07-16 18:32:03

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: help with scripts

Congratulations!  big_smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

Board footer