Posted: 29th Oct 2022 10:52
I can make a string saying like

Color as string:Color="Green"

Then I can check if color= another string that turns green.

But I can not check if there is not a match, like if the other string turned red and it can not be checkd if it matches.

So like

if Color=Player.Id then a action happens.

But there is no way to say

Here is some code for explinations.

If Color does not match green then something happens.

I am lost in strings lol.


here is can check if they match, but i do not know how to check if they do not match.
if SecondLevelColor=All_Balloons[A].SelectedColor_1 or FirstLevelColor=All_Balloons[A].SelectedColor_1 then Collected=Collected-1

+ Code Snippet
if  All_Balloons[A].UnderTheLine=1
All_Balloons[A].Time=-300
All_Balloons[A].XPos=random(10,750)
SetSpritePositionByOffset(All_Balloons[A].ID,All_Balloons[A].XPos,30)
if All_Balloons[A].Frame=1 then All_Balloons[A].SelectedColor_1="Red"
if All_Balloons[A].Frame=5 then All_Balloons[A].SelectedColor_1="Green"
if All_Balloons[A].Frame=9 then All_Balloons[A].SelectedColor_1="Yellow"
if All_Balloons[A].Frame=13 then All_Balloons[A].SelectedColor_1="Blue"
if All_Balloons[A].Frame=17 then All_Balloons[A].SelectedColor_1="Purple"
if All_Balloons[A].Frame=21 then All_Balloons[A].SelectedColor_1="Black"
 if SecondLevelColor=All_Balloons[A].SelectedColor_1 or FirstLevelColor=All_Balloons[A].SelectedColor_1 then Collected=Collected-1
PlaySound(sound_2,30,0,0)
All_Balloons[A].UnderTheLine=0
endif
Posted: 29th Oct 2022 14:35
Not sure I follow your question.. but just in case.. You can test for equality with the = operator and an inequality by using <> or possibly !=

One thing though; is that this block of code could probably be better represented as an array. So if you get more options; you can just look them.

+ Code Snippet
if All_Balloons[A].Frame=1 then All_Balloons[A].SelectedColor_1="Red"
if All_Balloons[A].Frame=5 then All_Balloons[A].SelectedColor_1="Green"
if All_Balloons[A].Frame=9 then All_Balloons[A].SelectedColor_1="Yellow"
if All_Balloons[A].Frame=13 then All_Balloons[A].SelectedColor_1="Blue"
if All_Balloons[A].Frame=17 then All_Balloons[A].SelectedColor_1="Purple"
if All_Balloons[A].Frame=21 then All_Balloons[A].SelectedColor_1="Black"
  



So some place prior to this sequence (in your setup code most likely) i'd make an array that stores this list of strings. Something like this.

ie.

Dim SelectedColorNames$(100)
SelectedColorNames$(1) = "Red"
SelectedColorNames$(5) = "Green"
SelectedColorNames$(9) = "Yellow"
SelectedColorNames$(13) = "Blue"
SelectedColorNames$(17) = "Purple"
SelectedColorNames$(21) = "Black"


Then the if / then logic becomes something more like this.

+ Code Snippet
       ThisColour$ =  SelectedColorNames$( All_Balloons[A].Frame )

       if ThisColour$&lt;&gt;""
             All_Balloons[A].SelectedColor_1  = ThisColour$
       else
             // not valid colour
       endif 

  



dunno, if that's what you're after or not..
Posted: 29th Oct 2022 21:21
Kevin Picone

HI, My code is in a set of arrays already Stating the . after each balloon.

I tried using <> and even just < and or > and I get a error becouse they are strings and not int.

This is why i posted this becouse I am confused, i thought using <> was the same as using = but it is not for some reason.

Im lost on strings.

You can check to see if strings are equal but not if they miss match.
Posted: 29th Oct 2022 23:30
i thought using <> was the same as using =

no. <> is "less than or greater than". aka NOT =.
+ Code Snippet
SetErrorMode(2)

// set window properties
SetWindowTitle( "Strings" )
SetWindowSize( 1280,720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1280,720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

GLOBAL MyString$, Strings as String [9]
Randomize()

do 
	If GetRawKeyPressed(27) then End

	If GetPointerPressed() then Randomize()
	
	Print("MyString = " + MyString$ + CHR(10) )

	For x = 0 to Strings.Length
		If Strings[x] &lt;&gt; MyString$
			Print( Strings[x] + " = No!" )
		ElseIf Strings[x] = MyString$
			Print( Strings[x] + " = Yes!" )
		EndIf
	Next x

	Print(CHR(10) + "Click!")
    Sync()
loop

Function Randomize()
	MyString$ = STR (Random(1,5) )
	For x = 0 to Strings.Length
		Strings[x] = STR (Random(1,5))
	Next x
EndFunction

if you're getting "strings and not int" then you are comparing (the 2) different variable types somehow.
Posted: 30th Oct 2022 1:03
Virtual Nomad

Thank you, I thought something was off and now that you show me this I am lost on why my code does not work, but I will use your code for my situation.

I will look at it and learn from it.

Right now i am learning about strings in the book and am trying diffrent things
Posted: 30th Oct 2022 2:42
Ok Virtual Nomad

I looked at your code in detail and you are assinging the stings with integers and then matching the numbers , i am not using numbers at all and only words.

This is my strings I am trying to match, no numbers to match.

if All_Balloons[A].Frame=1 then All_Balloons[A].SelectedColor_1="Red"
if All_Balloons[A].Frame=5 then All_Balloons[A].SelectedColor_1="Green"
if All_Balloons[A].Frame=9 then All_Balloons[A].SelectedColor_1="Yellow"
if All_Balloons[A].Frame=13 then All_Balloons[A].SelectedColor_1="Blue"
if All_Balloons[A].Frame=17 then All_Balloons[A].SelectedColor_1="Purple"
if All_Balloons[A].Frame=21 then All_Balloons[A].SelectedColor_1="Black"

All_Balloons[A].SelectedColor_1 can match All_Balloons[A].SelectedColor_1 But there is no way to check if they do not match, even in your example.

Untill i tried this and this is working and it is due to yoou.

if All_Balloons[A].YPos>100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 and FirstLevelColor<>color or All_Balloons[A].YPos>100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 and SecondLevelColor<>color
Collected=Collected-1
endif
Posted: 30th Oct 2022 2:56
you are assinging the stings with integers

i had to assign something as string and converting random integers was the easiest thing i came up with.

meanwhile:
+ Code Snippet
// Project: Strings 
// Created: 2022-10-29

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Strings" )
SetWindowSize( 1280,720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1280,720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

GLOBAL MyColor$, Colors as String []

Colors.Insert("Red")
Colors.Insert("Green")
Colors.Insert("Blue")
Colors.Insert("Yellow")
Colors.Insert("Cyan")
Colors.Insert("Magenta")

GLOBAL TheseColors as String [9]
Randomize()

do 
	If GetRawKeyPressed(27) then End

	If GetPointerPressed() then Randomize()
	
	Print("My Color = " + MyColor$ + CHR(10) )

	For x = 0 to TheseColors.Length
		If TheseColors[x] &lt;&gt; MyColor$
			Print( TheseColors[x] + " = No!" )
		ElseIf TheseColors[x] = MyColor$
			Print( TheseColors[x] + " = Yes!" )
		EndIf
	Next x

	Print(CHR(10) + "Click!")
    Sync()
loop

Function Randomize()
	MyColor$ = Colors[Random(0,Colors.Length)] 
	For x = 0 to TheseColors.Length
		TheseColors[x] = Colors[Random(0,Colors.Length)]
	Next x
EndFunction


good luck
Posted: 30th Oct 2022 3:34
Ok.

So i found this and it works just for this reason lol, never knew about it

CompareString

And i used it and found my error

For some reason, not known, thease two lines cancel each other out.

if All_Balloons[A].YPos>100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 and compare_1=0 or All_Balloons[A].YPos>100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 and compare_2=0
Collected=Collected-1
endif

if All_Balloons[A].YPos>100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 and compare_1=1 or All_Balloons[A].YPos>100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 and compare_2=1
Collected=Collected+1
endif

this is how I am using the compare function

compare_1=CompareString( FirstLevelColor, All_Balloons[A].SelectedColor_1,0,-1 )
compare_2=CompareString( SecondLevelColor, All_Balloons[A].SelectedColor_1,0,-1)

When i click on balloons not the color asked for it deletes collected, But when i click on the correct balloons it does nothing, but when i add a +2 it then adds so the bottom line does nothing for comparing against it unless i use your code and i am going to have to.

Here is the whole thing

+ Code Snippet
compare_1=CompareString( FirstLevelColor, All_Balloons[A].SelectedColor_1,0,-1 )
compare_2=CompareString( SecondLevelColor, All_Balloons[A].SelectedColor_1,0,-1)
if All_Balloons[A].Frame=1 then All_Balloons[A].SelectedColor_1="Red"
if All_Balloons[A].Frame=5 then All_Balloons[A].SelectedColor_1="Green"
if All_Balloons[A].Frame=9 then All_Balloons[A].SelectedColor_1="Yellow"
if All_Balloons[A].Frame=13 then All_Balloons[A].SelectedColor_1="Blue"
if All_Balloons[A].Frame=17 then All_Balloons[A].SelectedColor_1="Purple"
if All_Balloons[A].Frame=21 then All_Balloons[A].SelectedColor_1="Black"

if All_Balloons[A].YPos&gt;100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 and compare_1=0 or  All_Balloons[A].YPos&gt;100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 and compare_2=0
Collected=Collected-1
endif

if All_Balloons[A].YPos&gt;100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 and compare_1=1 or  All_Balloons[A].YPos&gt;100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 and compare_2=1
Collected=Collected+1
endif
Posted: 2nd Nov 2022 16:01
I have absolutely no clue what you're even trying to say in your posts, so based on your small code snippets are you trying to perform actions when all balloons of a certain color are selected? Also trying to perform an action on any balloon that isn't a specific color? Assuming a balloon's frame number corresponds with a color, then for the sake of efficiency, I'd ditch using strings altogether and set up some constants.

+ Code Snippet
#constant BALLOON_RED = 1
#constant BALLOON_GREEN = 5
#constant BALLOON_YELLOW = 9

if All_Balloons[A].Frame = BALLOON_RED then All_Balloons[A].SelectedColor_1 = BALLOON_RED
if All_Balloons[A].Frame = BALLOON_GREEN then All_Balloons[A].SelectedColor_1 = BALLOON_GREEN 



But, as you have more colors, your number of IF statements increases. Look for the pattern and reduce this for simplicity. Making another assumption, the balloons are made up of animations with each color having 4 frames. If that is true, then we can do the following:

+ Code Snippet
#constant BALLOON_RED = 0
#constant BALLOON_GREEN = 1
#constant BALLOON_YELLOW = 2
#constant BALLOON_BLUE = 3
#constant BALLOON_PURPLE = 4
#constant BALLOON_BLACK = 5

balloonColors as string[6]
balloonColors[BALLOON_RED ] = "red"
balloonColors[BALLOON_GREEN] = "green"
balloonColors[BALLOON_YELLOW] = "yellow"
balloonColors[BALLOON_BLUE] = "blue"
balloonColors[BALLOON_PURPLE] = "purple"
balloonColors[BALLOON_BLACK] = "black"

// All your IF statements have now been reduced to just this
baseFrame = floor((All_Balloons[A].Frame - 1) / 4)
All_Balloons[A].SelectedColor_1 = balloonColors[baseFrame)



So if you did want an actual string containing the color name, this would be a way to do it and its more manageable, easier to read, and a lot more expandable. But, storing the color name as a string for each balloon is a waste of memory as you could easily use this method above to find it whenever you need. I see no reason to maintain that data in your balloon structure.
Posted: 2nd Nov 2022 23:12
I have absolutely no clue what you're even trying to say in your posts


Im so sorry, I will to explain the best I can.

If there is no matching selected balloons then you get points taken away, that is a example of what it is im a trying to explain.

I think it is becouse all the other arrays info balloons are all 0 unless they are selected so you can not ask if selected level color does not match the selected balloon color.

I hope you understand.

So when i ask.

If selectedcolor <> levelcolor take point away , it looks at all the array and takes points away even if there is a match.
Posted: 14th Nov 2022 18:35
I think you're trying to explain it as if we know what your game is. Can you explain the actual game so we can understand what a selected balloon means.

Does the user select a balloon? Multiple balloons? What is level color?
Posted: 14th Nov 2022 18:59
explain it as if we know what your game is.


This was a game project i was trying but failed as it was for learning, I stoped the project all together.

I am on to my last project and it is looking real good and working perfect.

Thanks for asking anyhow