Errors that I don't know how to fix - scripting

#pragma strict
var targetscript : Diamond;
var yellow : Color(1,0.92,0.016,1);
var cyan : Color(0,1,1,1);
var green : Color(0,1,0,1);
var red : Color(1,0,0,1);
var magenta : Color(1,0,1,1);
var black : Color(0,0,0,1);
function Start () {
gameObject.camera.backgroundColor = yellow;
}
function Update () {
if (targetscript.score > 4) {
gameObject.camera.backgroundColor = Color.Lerp(yellow, cyan);
}
if (targetscript.score > 9) {
gameObject.camera.backgroundColor = Color.Lerp(cyan, green);
}
if (targetscript.score > 14) {
gameObject.camera.backgroundColor = Color.Lerp(green, red);
}
if (targetscript.score > 19) {
gameObject.camera.backgroundColor = Color.Lerp(red, magenta);
}
if (targetscript.score > 24) {
gameObject.camera.backgroundColor = Color.Lerp(magenta);
}
}
It gives me these errors:
Assets/Scripts/colour.js(4,22): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/Scripts/colour.js(4,22): BCE0044: expecting EOF, found '0.92'.
Assets/Scripts/colour.js(4,21): BCE0044: expecting ), found ','.
Assets/Scripts/colour.js(4,19): UCE0001: ';' expected. Insert a semicolon at the end.
I don't find any missing semicolons! I don't find anything wrong with the colors! why does it give me so many errors? I checked the script more than 5 times but I don't find anything wrong! Does anyone have any ideas? Thanks in advance

Since you are doing variable declaration with assignment to a class I think each of the color declaration need to look similar to this:
var yellow = new Color(1,0.92,0.016,1);
This creates a yellow variable with a Color type and we create a new instance of it and assign it to yellow.

var xxx: yyy = zzz;
This is how you declare a variable in Unityscript, where xxx is the name of the variable, yyy is the type of the variable and zzz is the value.
In your case, you wanted to define a type but you defined a value instead, thus the error appeared.
Change all of them to be:
var yellow : Color;
var cyan : Color;
var green : Color;
var red : Color;
var magenta : Color;
var black : Color;
Then in Start() function, give them value:
yellow = Color(1,0.92,0.016,1);
cyan = Color(0,1,1,1);
green = Color(0,1,0,1);
red = Color(1,0,0,1);
magenta = Color(1,0,1,1);
black = Color(0,0,0,1);

you could do it like this
#pragma strict
var targetscript : Diamond;
var yellow : Color = Color(1,0.92,0.016,1);
var cyan : Color = Color(0,1,1,1);
var green : Color = Color(0,1,0,1);
var red : Color = Color(1,0,0,1);
var magenta : Color = Color(1,0,1,1);
var black : Color = Color(0,0,0,1);
function Start () {
gameObject.camera.backgroundColor = yellow;
}
function Update () {
if (targetscript.score > 4) {
gameObject.camera.backgroundColor = Color.Lerp(yellow, cyan);
}
if (targetscript.score > 9) {
gameObject.camera.backgroundColor = Color.Lerp(cyan, green);
}
if (targetscript.score > 14) {
gameObject.camera.backgroundColor = Color.Lerp(green, red);
}
if (targetscript.score > 19) {
gameObject.camera.backgroundColor = Color.Lerp(red, magenta);
}
if (targetscript.score > 24) {
gameObject.camera.backgroundColor = Color.Lerp(magenta);
}
}

Related

Compose onValueChange behaviour isn't consistent

I'm making a sudoku game and solver. For my user interface I used LazyVerticalGrid to create a 9x9 grid. I successfully made it so when you click on a cell it will only accept digits [1-9] via an OutLinedTextField. I then added a conditional that only empty cells would have the text field applied. That worked and only those cells could be altered but when I do that the logic that only accepts digits doesn't work and the program crashes. If I comment out the conditional statement and the OutLinedTextField is applied to all cells it works again. I get the following error.
Also if I add conditionals for backgroundColor or Content Color the same thing happens and the program crashes if a non digit is pressed. I'm not sure why the conditionals affect the onValueChange logic. Why is this and how do I fix it?
fun displayPuzzle(answer: Array<Array<IntArray>>) {
var list: SnapshotStateList<String> = mutableStateListOf()
for (x in answer[0]) list.addAll(x.map { it.toString() })
var columnHeighty by remember { mutableStateOf(0F) }
var columnWidthx by remember { mutableStateOf(0f) }
var pad = 20.dp
LazyVerticalGrid(
columns = GridCells.Fixed(9),
contentPadding = PaddingValues(
start = pad,
top = pad,
end = pad,
bottom = pad
)
) {
items(list.size) { index ->
Card(
shape = RectangleShape,
backgroundColor = Color.Red,
modifier = Modifier
.requiredWidth(83.dp)
.fillMaxWidth()
.fillMaxHeight()
.onGloballyPositioned { coordinates ->
columnWidthx = coordinates.size.width.toFloat()
columnHeighty = coordinates.size.height.toFloat()
},
//backgroundColor = if (list[index].toInt() == 0) Color.Yellow else Color.White ,
//contentColor = if (list[index].toInt() == 0) Color.Blue else Color.Black ,
border = BorderStroke(width = 1.dp, color = Color.Black)
) {
Text(
text = list[index],
fontWeight = FontWeight.Bold,
fontSize = 30.sp,
color = Color(0xFF000000),
textAlign = TextAlign.Center,
modifier = Modifier
.padding(23.dp)
.clickable { }
)
}
// When the if statement is included the program crashes on a non digit entry
//if (list[index].toInt() == 0) {
val pattern = remember { Regex("[1-9]") }
var value by remember { mutableStateOf("") }
OutlinedTextField(
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
colors = TextFieldDefaults.outlinedTextFieldColors(cursorColor = Color.Transparent),
textStyle = TextStyle(color = Color.Red),
modifier = Modifier
.fillMaxHeight()
.padding(vertical = 10.dp, horizontal = 10.dp),
value = value,
onValueChange = { if (it.isEmpty() || (it.matches(pattern) && (it.length == 1)))
value = it
list[index] = value}
)
//}
}
}
Your game crashed because you trying to convert for example 'a' to Int value and runtime throws NumberFormatException.
You need to use:
if (list[index].toIntOrNull() == null)
This condition will be triggered if a non-decimical number is obtained from your SnapshotStateList
Explanation: toIntOrNull() returns Int from String (example: "4".toIntOrNull() - returns 4) otherwise it returns null

Two colors in one text field using Actionscript 2

I'm trying to get realtime rainbow text in a single word and reset to red when I space to the next word to create another rainbow word.
For instance, if I want to type the string, "his forgiveness", I want "h" to be red, "i" to be orange, "s" to be yellow, "f" to be red, "o" to be orange, "r" to be yellow, "g" to be green, "i" to be blue, "v" to be indigo, "e" to be violet. The remaining, "ness" can all be violet, I don't care. I just need the original concept down.
So far, I'm only able to change the color of the whole text area on a keypress(s) and not a single string character.
To fast forward to where I am, follow this quick 4 point process:
(1/4)Paste the following code on the stage.
counter = -1;
var key:Object = {onKeyDown:function () {
counter = counter+1;
if (counter == 1) {
inp.textColor = 0xFF0000;
}
if (counter == 2) {
inp.textColor = 0xFF9900;
}
if (counter == 3) {
inp.textColor = 0xFFFF00;
}
}};
Key.addListener(key);
(2/4)Make an input box with the instance name, "inp"
(3/4)Test the movie.
(4/4)Select the textbox and start typing in it.
I only have it changing the whole text box from your default color to red then orange than yellow. Getting a true rainbow code will be what I've long waited for if you can help.
In order to implement different colors on a single textfield you must use this properties on your textfield:
myTextField.html = true
myTextField.htmlText = 'bli bli bli<font color="#0000FF">bla bla bla/font>'
or you can use the TextFormat class to do so.
Here is how you can do.
tField.text = "bli bli bli";
var tFormat:TextFormat = new TextFormat();
tFormat.color = 0xff0000;
tField.setTextFormat(0,5,tFormat);
tFormat.color = 0x33cc33;
tField.setTextFormat(5,9,tFormat);
and in order to get the colors as you type use this class:
package {
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.events.KeyboardEvent;
import flash.events.Event;
public class ColorTextField extends TextField{
var tf:TextFormat = new TextFormat();
var ar:Array = new Array(0xFF0000,0x00FF00,0x0000FF,0x123456);
public function ColorTextField() {
// constructor code
this.type = TextFieldType.INPUT;
tf.size = 33;
this.defaultTextFormat = tf;
this.addEventListener(KeyboardEvent.KEY_UP,onKeyUp);
}
private function onKeyUp(event:KeyboardEvent):void{
var index:int = 0;
var colorIndex:int = 0;
while (index < this.text.length){
var char:String = this.text.substr(index,1);
if(char == " "){
colorIndex = 0;
}else{
tf.color = ar[colorIndex];
trace(index + "-" +ar[colorIndex]);
this.setTextFormat(tf,index,index+1);
colorIndex++;
if(colorIndex > ar.length-1){
colorIndex = ar.length-1;
}
}
index++;
}
}
}
}
this how you implement it.Create a new AS3 Fla and assign this as base class:
package {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldType;
public class MyClass extends MovieClip {
var tf:ColorTextField = new ColorTextField();
public function MyClass() {
// constructor code
tf.width = 500;
tf.text = "12345";
this.addChild(tf);
}
}
}
does not matter where you input the new text

Change highlight color of NSTableView selected row

how to change NSTable selected row background color?
here is good answer, but it is for uitable view .
For now,what I see is that I can change selected hilight style :
MyTAble.SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.Regular;
But here is only 3 options;
None = -1L,
Regular,
SourceList
I have tried following solution :
patientListDelegate.SelectionChanged += (o, e) => {
var r = PatientTableView.SelectedRow;
var v = PatientTableView.GetRowView (r, false);
v.Emphasized = false;
};
It works normally , but if I minimize and then open application again , still shows blue color
I found answer in objective-c
Change selection color on view-based NSTableView
Here is c# implementation:
inside delegate :
public override NSTableRowView CoreGetRowView (NSTableView tableView, nint row)
{
var rowView = tableView.MakeView ("row", this);
if (rowView == null) {
rowView = new PatientTableRow ();
rowView.Identifier = "row";
}
return rowView as NSTableRowView;
}
and custom row :
public class PatientTableRow : NSTableRowView
{
public override void DrawSelection (CGRect dirtyRect)
{
if (SelectionHighlightStyle != NSTableViewSelectionHighlightStyle.None) {
NSColor.FromCalibratedWhite (0.65f, 1.0f).SetStroke ();
NSColor.FromCalibratedWhite (0.82f, 1.0f).SetFill ();
var selectionPath = NSBezierPath.FromRoundedRect (dirtyRect, 0, 0);
selectionPath.Fill ();
selectionPath.Stroke ();
}
}
}

Setting values in aliased records

I'm just starting out with Elm, so be nice:)
In the "Random" example of the official Elm Guide the model seems to be initialized with the value 1 like this:
type alias Model =
{ dieFace : Int
}
init : (Model, Cmd Msg)
init =
(Model 1, Cmd.none)
My understanding of this is that the code
Model 1
sets the value of the dieFace attribute in the record. Is this correct and if so: what is this strange syntax for setting the attribute of a record? I would have expected something along the lines of
{ model | dieFace = 1 }
Model is a type alias for a record which has a single int value called dieFace.
There are a few ways to create a value of that type:
Model 1 -- treats Model as a function with a single parameter
{ dieFace = 1 } -- creates a record that happens to coincide with the Model alias
The strange syntax you see in { model | dieFace = 1 } is short-hand for creating a new value based off an existing record value but changing one or more fields. It perhaps doesn't make much sense when your record type has a single field so let's create an arbitrary example:
type alias ColoredDie = { dieFace: Int, color: String }
You can play around in the Elm REPL and perhaps this will help it make sense:
> blue3 = ColoredDie 3 "blue"
{ dieFace = 3, color = "blue" } : Repl.ColoredDie
> red3 = { blue3 | color = "red" }
{ dieFace = 3, color = "red" } : { dieFace : Int, color : String }
> red4 = { red3 | dieFace = 4 }
{ dieFace = 4, color = "red" } : { color : String, dieFace : number }
> green6 = { red4 | color = "green", dieFace = 6 }
{ dieFace = 6, color = "green" } : { color : String, dieFace : number }
You can read up on Elm's record syntax here.

Drawing a star in Rebol VID like in JavaFX

What's the equivalent of this javaFx star code in Rebol VID (need AGG for same effect I guess) ?
http://www.javafxgame.com/javafx-wish-tree/
(source: javafxgame.com)
/*
* Star.fx
*/
package wishtree;
import java.text.SimpleDateFormat;
import java.util.Date;
import javafx.scene.effect.DropShadow;
import javafx.scene.paint.*;
import javafx.scene.shape.Polygon;
import java.lang.Math.*;
/**
* #author Henry Zhang http://www.javafxgame.com
*/
public class Star extends Polygon {
public var name: String = "your name";
public var wish: String = "I want to ...";
public var time: String = getDateString();
public var email: String = "" ;
public var whichColor : Integer ;
def r1 : Double = 15;
def r2 : Double = r1 / 1.6;
var r = [r1, r2];
var strokeColor =
[ Color.PINK, Color.YELLOW, Color.GOLDENROD, Color.CYAN,
Color.PURPLE, Color.BLUEVIOLET, Color.CORAL, Color.CRIMSON ];
var fillColor =
[ Color.GOLD, Color.BLUE, Color.RED, Color.DARKSLATEBLUE,
Color.DARKORANGE, Color.MAGENTA, Color.BROWN, Color.CHOCOLATE ];
init {
// compute the coordinates of the star polygon
points = for ( i in [0..9] ) [
r[i mod 2] * cos( toRadians(i*36) ),
r[i mod 2] * sin( toRadians(i*36) )
];
blocksMouse = true;
strokeWidth = 1;
whichColor = random() * sizeof(strokeColor) as Integer;
effect = DropShadow { color: Color.WHITE };
changeStatus();
}
function getDateString() : String {
var formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
var date = new Date();
return formatter.format(date);
}
public function changeStatus() {
stroke = strokeColor[whichColor];
fill = LinearGradient {
startX: 0 startY: 0 endX: 0 endY: 1.0
proportional: true
stops: [
Stop { offset: 0.1 color: Color.WHITE }
Stop { offset: 1.0 color: fillColor[whichColor]}
]
};
}
}
Drawing a similar star in REBOL/View requires usage of the Draw dialect (it's a DSL) documented here. The FILL-PEN and POLYGON draw commands should do the job well.