Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / String Questions

Author
Message
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 29th Oct 2022 10:52 Edited at: 29th Oct 2022 10:57
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



Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 29th Oct 2022 14:35 Edited at: 30th Oct 2022 01:29
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.




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.




dunno, if that's what you're after or not..



PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
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.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 29th Oct 2022 23:30 Edited at: 29th Oct 2022 23:37
Quote: "i thought using <> was the same as using ="

no. <> is "less than or greater than". aka NOT =.

if you're getting "strings and not int" then you are comparing (the 2) different variable types somehow.
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 30th Oct 2022 01:03 Edited at: 30th Oct 2022 01:04
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
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 30th Oct 2022 02:42 Edited at: 30th Oct 2022 02:46
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
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 30th Oct 2022 02:56
Quote: "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:


good luck
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 30th Oct 2022 03:34 Edited at: 30th Oct 2022 03:38
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

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
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.



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:



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.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 2nd Nov 2022 23:12 Edited at: 2nd Nov 2022 23:12
Quote: "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.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
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?
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 14th Nov 2022 18:59
Quote: "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

Login to post a reply

Server time is: 2024-11-23 09:40:12
Your offset time is: 2024-11-23 09:40:12